/build/static/layout/Breadcrumb_cap_w.png

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.


0 Comments   [ + ] Show comments

Answers (4)

Answer Summary:
Posted by: adilrathore 11 years ago
4th Degree Black Belt
2

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 11 years ago
Posted by: adilrathore 11 years ago
4th Degree Black Belt
0

 '-=-=-=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 11 years ago
Posted by: maharaskal 11 years ago
White Belt
0
im getting error when run the script. Error on line 38 Char: 1 Error: The system cannot find the file specified. code: 80070002
Posted by: maharaskal 11 years ago
White Belt
0

I found the solution. thanks

OnErrorResumenext
Wsh.RunChr(34) & strDirectory & "\SysInfo.txt" &  Chr(34)'Open the SysInfo.txt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ