Forum

Notifications
Clear all

Scripting Error

0 Posts
2 Users
0 Reactions
204 Views
(@molliver)
New Member
Joined: 55 years ago
Posts: 2
Topic starter  

Hi,

I have the following script bound via key mapping to alt+shit+a. However everytime i run it i get the following error after it completes:
Keymapping script Error
*(null)" (0) on line 0 column 0: (null)

Any ideas how i can stop that?

Regards

Mark

VBSCRIPT
 Dim objShell, strPath, strRegReg, strRegKey, custcode, strSRVHost, StrHostName, strFileName, strClientCode
 set objFSO = CreateObject("Scripting.FileSystemObject")
 strFileName = "c:Network-log.txt"
set objOutputfile = objFSO.CreateTextFile( (strFileName) , True) 
 set objShell = CreateObject("WScript.Shell")
 
 MsgBox "About to Run Network Tests"
 objOutputfile.WriteLine(VbCrLf & " Tests Started on: " & Now & vbCrLf)
 objOutputfile.writeline (vbCrLf & "* Run Tests  *" & vbCrLf)
 objOutputfile.writeline ("* Computers IP Settings *")
  Ipconfig()
 objOutputfile.WriteLine(VbCrLf & "Test ended on: " & Now)
 objOutputfile.close
 MsgBox "Tests Completed, Please contact Support with a screenshot of your issue"
 objShell.Exec("notepad " & (strFileName) )

Function Ipconfig()
 set objExec = objShell.Exec("ipconfig /all" )
 strResults = LCase(objExec.StdOut.ReadAll)
 objOutputfile.writeline (strResults)
End Function

   
ReplyQuote
(@bpence)
Member Admin
Joined: 12 months ago
Posts: 1375
Topic starter  

Mark,

You always need a 'Sub Main / End Sub' around the main body of the script. The error you're getting (which should, admittedly be less cryptic) indicates a missing "Main". I've made the following modifications in the code:

1. Put Sub Main around the main body of the application
2. Move declarations outside of main. Some of these are shared with the Ipconfig function and need to be global.
3. Add objOutputfile to the declaration list. It is created in Main and used in Ipconfig
4. Included a path '\' in the assignment to strFileName. Otherwise, there's no telling where the file might actuall be.

Hope this helps.

Nice script, BTW.

Regards,

Brian

VBSCRIPT
 Dim objShell, strPath, strRegReg, strRegKey, custcode, strSRVHost, StrHostName, strFileName, strClientCode, objOutputfile

Sub Main
 set objFSO = CreateObject("Scripting.FileSystemObject")
 strFileName = "c:\\Network-log.txt"
set objOutputfile = objFSO.CreateTextFile( (strFileName) , True) 
 set objShell = CreateObject("WScript.Shell")
 
 MsgBox "About to Run Network Tests"
 objOutputfile.WriteLine(VbCrLf & " Tests Started on: " & Now & vbCrLf)
 objOutputfile.writeline (vbCrLf & "* Run Tests  *" & vbCrLf)
 objOutputfile.writeline ("* Computers IP Settings *")
  Ipconfig()
 objOutputfile.WriteLine(VbCrLf & "Test ended on: " & Now)
 objOutputfile.close
 MsgBox "Tests Completed, Please contact Support with a screenshot of your issue"
 objShell.Exec("notepad " & (strFileName) )
End Sub

Function Ipconfig()
 set objExec = objShell.Exec("ipconfig /all" )
 strResults = LCase(objExec.StdOut.ReadAll)
 objOutputfile.writeline (strResults)
End Function

   
ReplyQuote
(@molliver)
New Member
Joined: 55 years ago
Posts: 2
Topic starter  

Thanks, that solved the problem and works fine now even with the rest of the debug output i made with the script put back in place.

Regards

Mark


   
ReplyQuote
Share: