我正在编写此脚本以帮助我的工作场所重新映像计算机时进行日志记录。问题是我对VBS和VBS脚本故障排除方面缺乏经验。
此脚本用于接受参数并记录参数指示的部分。例如:有人传入/ 1,然后是脚本日志部分1.
这是完整的脚本(有一些元素被编辑)。
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Dim strDriveLetter, strRemotePath, strusername, strpassword, strRemoteNewPath
WScript.sleep 5000
Dim iRetVal
Dim sCmd
Dim begImg, begDrivers, begAppInstalls, finalCheck, finalConfig, complete
set begImg = WScript.Arguments
set begDrivers = WScript.Arguments
set begAppInstalls = WScript.Arguments
set finalCheck = WScript.Arguments
set finalConfig = WScript.Arguments
set complete = WScript.Arguments
'my solution
set sequence = Wscript.Arguments
sCmd = "Net use L: /del"
iRetVal = WshShell.Run(sCmd, 0, true)
strDriveLetter = "L:"
strRemotePath = "\\FileServ1\LogShare"
strRemoteNewPath = "\\FileServ1\LogShare"
strusername = "domain\admin"
strpassword = "password"
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, , strusername, strpassword
'|------------------------------------|
'| Get Serial Number |
'| Variable objSN = Machine Serial # |
'|------------------------------------|
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For each objBIOS in colBIOS
objSN = objBIOS.SerialNumber
Next
' This appears to be the first part 1
'|--------------------------------------|
'| Create Text File with Machine S/N |
'|--------------------------------------|
'8 is ForAppending
If sequence = 1 Then
Set trs = objFSO.OpenTextFile(strDriveLetter & "\" & objSN & ".txt", 8, True)
trs.WriteLine ""
trs.WriteLine "*************************************************************************"
trs.WriteLine(Now & " BEGINNING IMAGING SESSION ON: " & objSN)
trs.WriteLine(Now & " mapped " & strRemotePath & " as " & strDriveLetter)
trs.WriteLine(Now & " Beginning to apply image...")
trs.WriteLine ""
End If
If Err.Number <> 0 Then
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
trs.WriteLine(Now & ": Error: " & Err.Number )
trs.WriteLine(Now & ": Error (Hex): " & Hex(Err.Number ))
trs.WriteLine(Now & ": Source: " & Err.Source )
trs.WriteLine(Now & ": Description: " & Err.Description )
Err.Clear
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
End If
' Part 2
'|--------------------------------------|
'| BEGIN DRIVER AND WINDOWS UPDATES |
'|--------------------------------------|
If sequence = 2 Then
trs.WriteLine(Now & " IMAGE APPLIED; BEGINNING DRIVERS AND WINDOWS UPDATES...")
trs.WriteLine ""
End If
If Err.Number <> 0 Then
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
trs.WriteLine(Now & ": Error: " & Err.Number )
trs.WriteLine(Now & ": Error (Hex): " & Hex(Err.Number ))
trs.WriteLine(Now & ": Source: " & Err.Source )
trs.WriteLine(Now & ": Description: " & Err.Description )
Err.Clear
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
End If
'Part 3
'|----------------------------------------------------------|
'| APPLY UPDATES AND DRIVERS, GO TO APPLICATION INSTALLS |
'|----------------------------------------------------------|
If sequence = 3 Then
trs.WriteLine(Now & " INITIAL UPDATES AND DRIVERS APPLIED; PROCEEDING TO APPLICATION INSTALLS...")
End If
If Err.Number <> 0 Then
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
trs.WriteLine(Now & ": Error: " & Err.Number )
trs.WriteLine(Now & ": Error (Hex): " & Hex(Err.Number ))
trs.WriteLine(Now & ": Source: " & Err.Source )
trs.WriteLine(Now & ": Description: " & Err.Description )
Err.Clear
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
End If
'Part 4
'|--------------------------------------|
'| STARTING FINAL CHECKS |
'|--------------------------------------|
If sequence = 4 Then
trs.WriteLine(Now & " APPLICATIONS COMPLETE; STARTING FINAL CHECK FOR UPDATES...")
trs.WriteLine ""
End If
If Err.Number <> 0 Then
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
trs.WriteLine(Now & ": Error: " & Err.Number )
trs.WriteLine(Now & ": Error (Hex): " & Hex(Err.Number ))
trs.WriteLine(Now & ": Source: " & Err.Source )
trs.WriteLine(Now & ": Description: " & Err.Description )
Err.Clear
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
End If
'Part 5
'|--------------------------------------|
'| FINAL CONFIGURATIONS |
'|--------------------------------------|
'8 is ForAppending
'Set trs = objFSO.OpenTextFile(strDriveLetter & "\" & objSN & ".txt", 8, True) - I might need to delete this to make sure its on the same txt file
If sequence = 5 Then
trs.WriteLine(Now & " UPDATES COMPLETE; PROCEEDING TO FINAL CONFIGURATIONS...")
trs.WriteLine ""
End If
If Err.Number <> 0 Then
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
trs.WriteLine(Now & ": Error: " & Err.Number )
trs.WriteLine(Now & ": Error (Hex): " & Hex(Err.Number ))
trs.WriteLine(Now & ": Source: " & Err.Source )
trs.WriteLine(Now & ": Description: " & Err.Description )
Err.Clear
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
End If
'Part 6
'this should be the final part
'|--------------------------------------|
'| IMAGING SESSION COMPLETE |
'|--------------------------------------|
If sequence = 6 Then
trs.WriteLine(Now & " FINAL CONFIGURATION COMPLETE; IMAGING SESSION COMPLETE...")
trs.WriteLine "*************************************************************************"
'Use netbeans to remove the following 4 spaces if necessary
trs.WriteLine ""
trs.WriteLine ""
trs.WriteLine ""
trs.WriteLine ""
End If
If Err.Number <> 0 Then
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
trs.WriteLine(Now & ": Error: " & Err.Number )
trs.WriteLine(Now & ": Error (Hex): " & Hex(Err.Number ))
trs.WriteLine(Now & ": Source: " & Err.Source )
trs.WriteLine(Now & ": Description: " & Err.Description )
Err.Clear
trs.WriteLine("<<<<<<<<<<<<<<<<<<<<<----------ERROR---------->>>>>>>>>>>>>>>>>>>>>")
End If
trs.close
wscript.quit
以下是我的输入:cscript OneScriptRuleThemAll.vbs /1
以下是输出和错误消息:OneScriptToRuleThemAll.vbs(55, 1) Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment
据我所知,我没有输入错误数量的论点,我也没有看到我的财产分配问题。
任何和所有帮助将不胜感激。
答案 0 :(得分:0)
你为什么要张贴所有废话。
您的论据是一个集合,所以格式为
Set Arg = WScript.Arguments
If LCase(Arg(0)) = "menu" or LCase(Arg(0)) = "m" then
ShowMenu
...
1是0,2是1等
答案 1 :(得分:0)
我认为错误发生在If sequence = 1 Then
行上。为了您的工作意图,您需要将其更改为If sequence.Item(0) = 1 Then
你的论点可以继续从1到6。
答案 2 :(得分:0)
在我看来if语句没有用于正确输入参数。为什么每次都有错误检查?它似乎只是一个很大的if声明。