VBScript Error! Need Help!!
Hi guys its giving error on the path. kindly assist me on this. thanks in advance.
'-=-=-=Create Folder=-=-=-=-=-
Dim oShell, oEnv, oFS, strDirectory
Set oShell = CreateObject("wscript.Shell")
set oFS = CreateObject("scripting.FileSystemObject")
Set oEnv = oShell.Environment("Process")
strDirectory = oEnv("USERPROFILE") & "\Desktop\VBSLab"
if not oFS.FolderExists(strDirectory) then oFS.CreateFolder(strDirectory)
'-=-=-==-=-=-=-=Retrive sysinf0 & save in txt n open the file =-=-=-=-=-=
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TextFile = FSO.OpenTextFile("%USERPROFILE%") & "\desktop\vbslab\SysInfo.txt", 2, True) ' Error at here
Dim Wsh
Set Wsh = WScript.CreateObject("WScript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
TextFile.Writeline "OS Name: " & objOperatingSystem.Name
TextFile.Writeline "Version: " & objOperatingSystem.Version
TextFile.Writeline "OS Manufacturer: " & objOperatingSystem.Manufacturer
TextFile.Writeline "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
Set TextFile = Nothing
Set FSO = Nothing
Wsh.Run ("%USERPROFILE%") & "\desktop\vbslab\SysInfo.txt", 1 ' Another Error at here also.
WScript.Sleep 800 ' Delay allows Notepad to get the focus.
Answers (4)
I think it finally opens Sysinfo.txt with the input like below:
OS Name: Microsoft Windows 7 Enterprise |C:\windows|\Device\Harddisk0\Partition2
Version: 6.1.7601
OS Manufacturer: Microsoft Corporation
OS Name: 4087852
Here is the remediated code:
'-=-=-=Create Folder=-=-=-=-=-
Dim oShell, oEnv, oFS, strDirectory
Set oShell = CreateObject("wscript.Shell")
set oFS = CreateObject("scripting.FileSystemObject")
Set oEnv = oShell.Environment("Process")
strDirectory = oEnv("USERPROFILE") & "\Desktop\VBSLab"
if not oFS.FolderExists(strDirectory) then oFS.CreateFolder(strDirectory)
'-=-=-==-=-=-=-=Retrive sysinf0 & save in txt n open the file =-=-=-=-=-=
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TextFile = FSO.OpenTextFile(strDirectory & "\SysInfo.txt", 2, True)
Dim Wsh
Set Wsh = WScript.CreateObject("WScript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
TextFile.Writeline "OS Name: " & objOperatingSystem.Name
TextFile.Writeline "Version: " & objOperatingSystem.Version
TextFile.Writeline "OS Manufacturer: " & objOperatingSystem.Manufacturer
TextFile.Writeline "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
Set TextFile = Nothing
Set FSO = Nothing
Wsh.Run strDirectory & "\SysInfo.txt", 1, True
WScript.Sleep 800 ' Delay allows Notepad to get the focus.
Comments:
-
im getting error when run the script.
Error on line 38
Char: 1
Error: The system cannot find the file specified.
code: 80070002 - maharaskal 12 years ago
'-=-=-=Create Folder=-=-=-=-=-
Dim oShell, oEnv, oFS, strDirectory
Set oShell = CreateObject("wscript.Shell")
set oFS = CreateObject("scripting.FileSystemObject")
Set oEnv = oShell.Environment("Process")
strDirectory = oEnv("USERPROFILE") & "\Desktop\VBSLab"
if not oFS.FolderExists(strDirectory) then oFS.CreateFolder(strDirectory)
'-=-=-==-=-=-=-=Retrive sysinf0 & save in txt n open the file =-=-=-=-=-=
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TextFile = FSO.OpenTextFile(strDirectory & "\SysInfo.txt", 2, True) ' Error at here
Dim Wsh
Set Wsh = WScript.CreateObject("WScript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
TextFile.Writeline "OS Name: " & objOperatingSystem.Name
TextFile.Writeline "Version: " & objOperatingSystem.Version
TextFile.Writeline "OS Manufacturer: " & objOperatingSystem.Manufacturer
TextFile.Writeline "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
Set TextFile = Nothing
Set FSO = Nothing
Wsh.Run strDirectory & "\SysInfo.txt", 1, True ' Another Error at here also.
WScript.Sleep 800 ' Delay allows Notepad to get the focus.
Comments:
-
Formatted the vbscript as code!!! - adilrathore 12 years ago