Im getting this error when i try to run my vbs script,
object doesnt support this property or method
My vbs code is
Rem -- This example will show you how to create a very simple runonce configuration.
Rem -- Get current path of this script.
Set fso = CreateObject("Scripting.FileSystemObject")
currentdir = fso.GetAbsolutePathName(".")
Rem -- Read the info xml
Set xmldom = CreateObject("MSXML.DOMDocument")
xmldom.Load("c:\Montupet\PDF" & "\info.xml")
Rem -- Get the program id of the automation object.
progid = xmldom.SelectSingleNode("/xml/progid").text
Rem -- Create the COM object to control the printer.
set obj = CreateObject(progid)
Rem -- Get the default printer name.
Rem -- You can override this setting to specify a specific printer.
printername = "PDF Writer - bioPDF"
runonce = obj.GetSettingsFileName(true)
^
Error here
set oArgs=wscript.Arguments
Rem -- Print all the files in the 'in' folder
dim file_name, template
dim command_line_args
set command_line_args = wscript.Arguments
'Check if any Arguments have been passed to our script.
if command_line_args.count > 0 then
file_name = command_line_args(0)
template = command_line_args(1)
Set oWd = CreateObject("Word.Application")
oWd.Visible = False
wordname = """" & "c:\MTMS\MTMSPRT\" & file_name & """"
wscript.echo wordname
Set oDoc = oWd.Documents.Open(wordname)
Set oPS = oDoc.PageSetup
' Reduce the margins to .5" (36 points)
oPS.LeftMargin = 8.4
oPS.RightMargin = 0.2
'Save changes to doc on closing and quit Word
oDoc.Saveas wordname , 0
wscript.echo "Saved"
oDoc.Close
wscript.echo "close"
oWd.Quit
wscript.echo "Quit"
Set oWd = Nothing
Set objShell = Nothing
wscript.echo "Cleared Word"
Set oWd = Nothing
Set objShell = Nothing
output = "c:\MTMS\MTMSPRT\PDFs\" & Replace(ucase(file_name), "DOC", "") & "PDF"
Rem -- Set the values
obj.Init
obj.SetValue "Output", output
obj.SetValue "ShowSettings", "never"
obj.SetValue "ShowPDF", "no"
obj.SetValue "ShowProgress", "no"
obj.SetValue "ShowProgressFinished", "no"
obj.SetValue "SuppressErrors", "no"
obj.SetValue "ConfirmOverwrite", "no"
obj.SetValue "superimpose", template
Rem -- Write settings to the runonce-Invoice.ini
obj.WriteSettings True
wscript.echo "runonce created"
Rem -- Print the document
printfile = "c:\MTMS\MTMSPRT\" & file_name
cmd = """" & "c:\Montupet\PDF\printto.exe"" """ & printfile & """ """ & printername & """"
wscript.echo "printfile line setup"
Set WshShell = WScript.CreateObject("WScript.Shell")
ret = WshShell.Run(cmd, 1, true)
wscript.echo "shell run start"
Rem -- Wait until the runonce is removed.
Rem -- When the runonce is removed it means that the gui.exe program
rem -- has picked up the print job and is ready for the next.
While fso.fileexists(runonce)
wscript.echo "checking for runonce"
Rem -- Wait for some milliseconds before testing again
wscript.sleep 100
Wend
wscript.echo "runonce gone"
end if
Rem -- Dispose the printer control object
set obj = Nothing
Judging by this blog post for VB6,
runonce = obj.GetSettingsFileName(true)
should instead be
runonce = obj.GetSettingsFilePath(true)
The BioPDF website has a reference which might help further.
Related
I am preparing vbscript to run bat files where bat file name contains version number, Script have to search for bat file with matching version name . Once Ran,The result Text file will be generated with same version number. I have to search for Text file with same version number and read the txt file for error or msg, if error found i want to display it.
I know my requirement is little too much.
But I am finding little difficulty in debugging the code.I am stuck.
Can any one help me to resolve the issue.
Thank You
here is my script,
I am passing values for sql query from excel sheet.
Dim Ver, Version_Number
Dim con
Dim rs
Set con=createobject("adodb.connection")
Set rs=Createobject("adodb.recordset")
Set PinXL = CreateObject("Excel.application")
Set PinWB = PinXL.Workbooks.Open("C:\maspects\Trial.xls") '// Login and Enable Debug Window in application
Set PinWS = PinWB.Worksheets("Sheet1")
varr = Cstr(PinWS.Cells(2,1).Value)
varr1 = trim(varr)
usename = Cstr(PinWS.Cells(2,2).Value)
UN = trim(usename)
password = Cstr(PinWS.Cells(2,3).Value)
PWD = trim(password)
IrisDB = Cstr(PinWS.Cells(2,4).Value)
DB = trim(IrisDB)
Site_Name = Cstr(PinWS.Cells(2,5).Value)
Site = trim(Site_Name)
con.open"provider=sqloledb.1;server=" & varr1 & ";uid=" & UN & ";pwd=" & PWD & ";database=" & DB &""
Wscript.sleep 1000*3
rs.Open "select * from tblSettingsUnique where [Setting Name] like '%Revision%'" ,con
Wscript.sleep 1000*2
Version_Number = rs.Fields("Setting Value")
Ver = Version_Number
msgbox Ver
Call Execute
PinWB.Save
PinWB.Close
PinXL.Quit
Wscript.Quit
Function Execute
If Ver < PinWS.Cells(2,6).Value = "True" Then ' if Ver is less than Cell(2,6) value then application should come out of loop
For i = Ver to PinWS.Cells(2,6).Value step 1
msgbox i
Set WShell = CreateObject("WScript.Shell")
For each f in Wshell.Getfolder("C:\maspects\DB_script").Files
BatFile = instr(f.File , "4_0_"&i )
WShell.Run ("CMD /K C:\maspects\DB_script\"&batFile &".bat" & Varr1 &" "& UN &" "& password )
Call msg
Next
Next
End If
End Function
Function msg
Set TxtObject = CreateObject("scripting.FileSystemObject")
For each ResFile in TxtObject.GetFolder("C:\maspects\DB_script").Files
TargetFile = InStr(ResFile.File , "4_0_"&i )
Set TxtFile = TxtObject.openTextFile("C:\maspects\DB_script\"&TargetFile, 1 ,true)
Do until TxtFile.AtEndOfStream
For each F in TxtFile.Readline
if InStr (F,"msg" ) = "True" and InStr (F,"msg 207" )= "False" Then
msgbox "Error in:"&TargetFile
React =Cint(Inputbox("Go through the Result file:"&TargetFile &"Enter '1' to Continue '0' to Quit"))
If React = "0" Then
TextObject.Close
Wscript.Quit
End if
End If
Next
Loop
TextObject.Close
Next
End Function
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
Im having an issue where i am trying to create shortcuts but the vbs script is cutting out when it reaches a space in the path.
i have had a look around but many of the ones i have seen deal with the string being in vbs not being passed from a batch file.
here is my code so you can get a better understanding
Batch File:
#echo off
set office7="C:\ProgramData\Microsoft\Windows\Start Menu\Strategix Programs\Office Programs"
mkdir %office7%
cscript "H:\Installation Batch Files\createLink.vbs" ""%office7%\Purchase Order Entry.lnk"" "\\192.168.0.7\Temp\stock\Porder10.exe" "T:\Stock"
pause
Vbs file:
Set oShell = CreateObject("WScript.Shell") Set args = WScript.Arguments
sShortcut = oShell.ExpandEnvironmentStrings("" & args.Item(0) & "") sTarget = args.Item(1) sStartIn = args.Item(2)
WScript.Echo "Shortcut: " & sShortcut WScript.Echo "Target: " & sTarget WScript.Echo "StartIn: " & sStartIn
Output:
Shortcut: C:\ProgramData\Microsoft\Windows\Start Menu\Strategix Programs\Office Programs\Purchase
Target: Order
StartIn: Entry.lnk
Batch part
#echo off
set "office7=C:\ProgramData\Microsoft\Windows\Start Menu\Strategix Programs\Office Programs"
mkdir "%office7%"
cscript "H:\Installation Batch Files\createLink.vbs" "%office7%\Purchase Order Entry.lnk" "\\192.168.0.7\Temp\stock\Porder10.exe" "T:\Stock"
pause
The "correct" way of dealing with quotes is not include them in the value. If later you need them, adding them is easy (look the mkdir command and the arguments), but removing them is not. Without a good reason, do not include them. So, the "correct" way is
set "var=value"
That will assign the value to the variable, take care of problematic characters (all the assignation is inside quotes) and keep possible spaces at the end of the line out of the variable value.
Now, to the vbs part
Dim oShell
Set oShell = CreateObject("WScript.Shell")
Dim args
Set args = WScript.Arguments
Dim sShortcut, sTarget, sStartIn
sShortcut = args.Item(0)
sTarget = args.Item(1)
sStartIn = args.Item(2)
WScript.Echo "Shortcut: " & sShortcut
WScript.Echo "Target: " & sTarget
WScript.Echo "StartIn: " & sStartIn
There is no need for ExpandEnvironmentStrings, this has been done when the batch line was parsed in cmd. %office7% is a reference to the value of the variable, not the name of the variable, and the parser replaces variable reads with variable values.
And for the shortcut creation
With oShell.CreateShortcut( sShortcut )
.TargetPath = sTarget
.WorkingDirectory = sStartIn
.Save
End With
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
I use this snippet in vbscript:
Set WSH = CreateObject("WScript.Shell")
cmd = "some command"
flag = WSH.Run(cmd, 0, true)
As it can be noticed, in .Run() call, "WaitOnReturn" is set to "true" as I want to know when external program finishes and additionally it status
Problem is that external program needs some time to finish and I want to pop "Please wait..." MsgBox but I can't this way as I set "WaitOnReturn" on "true" which I need as I need result from that program for additional processing
Is there a way I can show somehow this MsgBox while external program is executed?
Sorry, it slipped to me that i can call MsgBox just before executing, Run()
:embarrassed:
Edit:
for no user interaction here is one workaround (taken from http://www.robvanderwoude.com/vbstech_ui_progress.php)
Function ProgressMsg( strMessage, strWindowTitle )
' Written by Denis St-Pierre
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strTEMP = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
If strMessage = "" Then
On Error Resume Next
objProgressMsg.Terminate( )
On Error Goto 0
Exit Function
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTempVBS = strTEMP + "\" & "Message.vbs"
Set objTempMessage = objFSO.CreateTextFile( strTempVBS, True )
objTempMessage.WriteLine( "MsgBox""" & strMessage & """, 4096, """ & strWindowTitle & """" )
objTempMessage.Close
On Error Resume Next
objProgressMsg.Terminate( )
On Error Goto 0
Set objProgressMsg = WshShell.Exec( "%windir%\system32\wscript.exe " & strTempVBS )
Set wshShell = Nothing
Set objFSO = Nothing
End Function
Then call it with:
ProgressMsg "Installing, Please wait.", "Some title"
end terminate it with:
ProgressMsg "", "Some title"
I was given an answer on another blog, basically, all I had to do was dim the variable "ProgressMsg" globally.
Thanks