Page 1 of 2

Technet Microsoft: Computer name script

Posted: Mon Mar 19, 2012 6:25 am
by nanodroid
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

Technet Microsoft: Computer name script

Posted: Mon Mar 19, 2012 6:25 am
by nanodroid
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

Technet Microsoft: Computer name script

Posted: Mon Mar 19, 2012 6:34 am
by rasimmer
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

Technet Microsoft: Computer name script

Posted: Tue Mar 20, 2012 1:26 am
by rasimmer
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.

Technet Microsoft: Computer name script

Posted: Tue Mar 20, 2012 2:48 am
by rasimmer
It's %computername%, not $computername%

Technet Microsoft: Computer name script

Posted: Tue Mar 20, 2012 3:02 am
by jvierra
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.



Technet Microsoft: Computer name script

Posted: Tue Mar 20, 2012 3:08 am
by nanodroid
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.

Technet Microsoft: Computer name script

Posted: Tue Mar 20, 2012 3:57 am
by nanodroid
Thanks I will get these books very soon thanks for the information.

Technet Microsoft: Computer name script

Posted: Wed Mar 21, 2012 8:16 am
by nanodroid
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

Technet Microsoft: Computer name script

Posted: Wed Mar 21, 2012 8:40 am
by nanodroid
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.