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.
This topic is 12 years and 5 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
nanodroid
Posts: 12
Last visit: Thu Mar 22, 2012 6:19 am

Technet Microsoft: Computer name script

Post 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
User avatar
nanodroid
Posts: 12
Last visit: Thu Mar 22, 2012 6:19 am

Technet Microsoft: Computer name script

Post 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
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Technet Microsoft: Computer name script

Post 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
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Technet Microsoft: Computer name script

Post 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.
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Technet Microsoft: Computer name script

Post by rasimmer »

It's %computername%, not $computername%
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Technet Microsoft: Computer name script

Post 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.


User avatar
nanodroid
Posts: 12
Last visit: Thu Mar 22, 2012 6:19 am

Technet Microsoft: Computer name script

Post 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.
User avatar
nanodroid
Posts: 12
Last visit: Thu Mar 22, 2012 6:19 am

Technet Microsoft: Computer name script

Post by nanodroid »

Thanks I will get these books very soon thanks for the information.
User avatar
nanodroid
Posts: 12
Last visit: Thu Mar 22, 2012 6:19 am

Technet Microsoft: Computer name script

Post 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
User avatar
nanodroid
Posts: 12
Last visit: Thu Mar 22, 2012 6:19 am

Technet Microsoft: Computer name script

Post 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.
This topic is 12 years and 5 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked