Technet Microsoft: Computer name script

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
nanodroid
Posts: 12
Joined: Thu Feb 24, 2011 3:10 am

Technet Microsoft: Computer name script

Post by nanodroid » Mon Mar 19, 2012 6:25 am

I have a script that I grabbed from the Technet Microsoft website. It works fine but I would like to know how to change the echo command a command that will allow it to get the information, then send it to notepad.exe and then print the information in the notepad.

Here it is:

Code: Select all

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
WScript.Echo "Computer Name: " & strComputerName

User avatar
nanodroid
Posts: 12
Joined: Thu Feb 24, 2011 3:10 am

Technet Microsoft: Computer name script

Post by nanodroid » Mon Mar 19, 2012 6:25 am

I have a script that I grabbed from the Technet Microsoft website. It works fine but I would like to know how to change the echo command a command that will allow it to get the information, then send it to notepad.exe and then print the information in the notepad.

Here it is:

Code: Select all

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
WScript.Echo "Computer Name: " & strComputerName

User avatar
rasimmer
Posts: 182
Joined: Fri Jan 30, 2009 12:37 am

Technet Microsoft: Computer name script

Post by rasimmer » Mon Mar 19, 2012 6:34 am

You can use the FileSystemObject (FSO) to manipulate files. Do some research on .OpenTextFile. Your logic would be more like get computer, create (or modify) text file, use WSHShell.Run to open the txt file "notepad C:mytext.txt"rasimmer2012-03-19 13:47:24

User avatar
rasimmer
Posts: 182
Joined: Fri Jan 30, 2009 12:37 am

Technet Microsoft: Computer name script

Post by rasimmer » Tue Mar 20, 2012 1:26 am

I was sticking the VbScript, but if you just want a way to do it you can also use Powershell:

$file = "C:Testmycomputer.txt"$env:computername | out-file -filepath $file -force | notepad $file

Maybe JVierra can show me a way to make it a one-liner. Powershell allows you to pipe information to the next command. Out-File doesn't return anything, so that is why I had to make it 2 lines, but another example.

User avatar
rasimmer
Posts: 182
Joined: Fri Jan 30, 2009 12:37 am

Technet Microsoft: Computer name script

Post by rasimmer » Tue Mar 20, 2012 2:48 am

It's %computername%, not $computername%

User avatar
jvierra
Posts: 13302
Joined: Tue May 22, 2007 9:57 am
Contact:

Technet Microsoft: Computer name script

Post by jvierra » Tue Mar 20, 2012 3:02 am

Sorry about the typo.

You need to get a book on basic WIndows so you will understand what al of this is. Without that you will be guessing forever.



User avatar
nanodroid
Posts: 12
Joined: Thu Feb 24, 2011 3:10 am

Technet Microsoft: Computer name script

Post by nanodroid » Tue Mar 20, 2012 3:08 am

jvierra what do you think about the book VBScript WMI,and ADSI unleashed. I bought this book and have been studying it for about a month.

User avatar
nanodroid
Posts: 12
Joined: Thu Feb 24, 2011 3:10 am

Technet Microsoft: Computer name script

Post by nanodroid » Tue Mar 20, 2012 3:57 am

Thanks I will get these books very soon thanks for the information.

User avatar
nanodroid
Posts: 12
Joined: Thu Feb 24, 2011 3:10 am

Technet Microsoft: Computer name script

Post by nanodroid » Wed Mar 21, 2012 8:16 am

One more question can you guys assist me on this script. I can get all of the information to display via Wscript.Echo.
But what I really want it to do is display the information all together without pressing Ok on every msgbox. Here is the script.

Code: Select all

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:FSO")
Wscript.Echo "Date created: " & objFolder.DateCreated
Wscript.Echo "Date last accessed: " & objFolder.DateLastAccessed
Wscript.Echo "Date last modified: " & objFolder.DateLastModified
Wscript.Echo "Drive: " & objFolder.Drive
Wscript.Echo "Is root folder: " & objFolder.IsRootFolder
Wscript.Echo "Name: " & objFolder.Name
Wscript.Echo "Parent folder: " & objFolder.ParentFolder
Wscript.Echo "Path: " & objFolder.Path
Wscript.Echo "Short name: " & objFolder.ShortName
Wscript.Echo "Short path: " & objFolder.ShortPath
Wscript.Echo "Size: " & objFolder.Size
Wscript.Echo "Type: " & objFolder.Type

User avatar
nanodroid
Posts: 12
Joined: Thu Feb 24, 2011 3:10 am

Technet Microsoft: Computer name script

Post by nanodroid » Wed Mar 21, 2012 8:40 am

It worked fine the information did display within the command prompt windows. But lets' say that I wanted that information to display in notepad.exe....is that possible.

Locked