Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fairly easy script?

Status
Not open for further replies.

Techie64

Technical User
Mar 22, 2005
29
0
0
US
Can someone provide a script example of how to open/run a file, to include the path? For example, if the path is C:\program files\designs\file.txt, how do I tell the script to open it? Also, will this work for all executable extensions (.exe, .cmd, .txt, .vbs, etc)? Thanks.
 
Here, this script gives an example of opening a textfile, reading the contents of the file and then using those contents elsewhere in the script.

Code:
On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
	Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
		for each OpSys in OpSysSet
			OpSys.Reboot()
 		next
Next

Just include the full path to the file. If the file exists in the same directory as the script then no path is needed.

This is not the same for other extension types. If you wish to run an EXE you will need to use WshShell.Run(exename)

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top