VBScript Error on Second Run

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

VBScript Error on Second Run

Post by kpassaur » Thu Jun 03, 2010 10:12 am

I am modifing a ver 11 script to ver 12. The dialog has a button that shuts down a process. When loading it sees if the process is running if so the button says shut down, if not running it says run program.

If runnning when pressed the process is shut down and the menu remains, if not running the processed and the menu closes. To check to see if it is running I use VBScript and it works. However, when I call the same VBScript command again it gives me an error which it did not used to do.

So, the same line and syntax works one time but the second time called it fails.

Here is the code if someone can figure out why.

// COMPILE_OPTS|C:\Program Files\eDocfile\File One\File One Main Menu.exe|\\X-series\keith\Files\Icons\pdffiler.ico|CONSOLE=0|INCLUDES=1| /LOGFILE=\dev\nul /NOSTOPKEY /NOSYSTRAY

RegistryReadKey>HKEY_LOCAL_MACHINE,SOFTWARE\eDocFile\File One,AppFolder,ProgramFolder

Let>APP_TITLE=File One
Let>Productname=File One

VBSTART
'returns the number of copies of ProcessName that are running
'will return 0 if ProcessName is not running
Function IsProcessRunning(ProcessName)
Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = oWMIService.ExecQuery ("Select Name from Win32_Process where Name='" & ProcessName & "'")
IsProcessRunning = colProcessList.count
End Function

Sub killProcess(pgm)
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process " & "where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Sub

Function GetFolder(Folder)
Set WShell = CreateObject("WScript.Shell")
GetFolder = WShell.SpecialFolders(Folder)
Set WShell = Nothing
End Function
VBEND

VBEval>GetFolder("AppData"),AppData
Let>settinsdir=%AppData%\edocfile\File One

Dialog>Dialog1
object Dialog1: TForm
Left = 331
Top = 207
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'Registered to %License%'
ClientHeight = 253
ClientWidth = 351
Color = clWhite
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object msLabel1: TLabel
Left = 129
Top = 22
Width = 93
Height = 16
Caption = 'File One'
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Gotthard'
Font.Style = []
ParentFont = False
Transparent = True
end
object msLabel2: TLabel
Left = -565
Top = 34
Width = 914
Height = 24
Caption =
'________________________________________________________________' +
'___________________'
Font.Charset = DEFAULT_CHARSET
Font.Color = clRed
Font.Height = -19
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
Transparent = True
end
object msLabel3: TLabel
Left = 20
Top = 84
Width = 310
Height = 13
Caption = '___________________ Program Operation _________________'
Transparent = True
end
object msLabel4: TLabel
Left = 20
Top = 144
Width = 311
Height = 13
Caption = '_____________________ Configuration ___________________'
Transparent = True
end
object msLabel5: TLabel
Left = 89
Top = 237
Width = 173
Height = 13
Caption = 'Copyright'#169' eDocFile Inc. 2004-2010'
Transparent = True
end
object MSImage1: tMSImage
Left = 8
Top = 16
Width = 41
Height = 25
Picture.Data = {
0D544C4D44504E474F626A65637489504E470D0A1A0A0000000D494844520000
00240000001B08020000009B4EBAB7000000017352474200AECE1CE900000004
67414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8
64000001E04944415478DAD5965455BF33B694AA10DB60847804A59114713181
405190E59AE1A16E416F8345A0818A9118A4B44B193DAE9D733B867F685D7BFD
EB19C31ED75CB0FE3965DB139B0C62BB45369AB6988CFE308933A7E72602E01B
2B2E4E17F1389C1972623FA306C19F6922DA4EB25221471EF25AB7D72D780B18
1D30037616383FF12E6853DF67467ECF6ED1C53F4BFF3D6FAD1AB5379DBE1326
FE9E86FE47BEDBCBDFC5DB24696EA4FCF5CFC5BB07D6ABFABC5D78ED75044A18
CB926E764B92D5D76C34689744A40E7A541771625BD2971D430577749FD5EF5B
09519F0C55368B3692A60660DCB745153D232CCB69CF788D0DCF95ABACDB375B
89BFB66ACE0CA715289DA5F33957773BC5CE291E1408605E978E98FF23CF91CF
BF7989315679AFBD91030BF913E95F55809ECD0D695ACAF86A17868C5D8FE9C0
AA5D475EDDAAAE3A49BA6B43A595DCCA9A93AD7B169307FEAD6BE1BEAF23E4C0
447F83FB5723A5A24FF21C71F7F4CBF756E738BA4A3B984B19ED9A03EC63DE85
619D0DD935565FA5542D29AFA2879C64EB56C9B653C466CD2FDB59ECE150FE13
86C8A5FF8AFF26B13DB9515971DBE616BA4272162F55B814BD753751219729EB
B619FC7A35244E7D5F79ED5679FB8DD122C955A85564E6515AFB867DB6ED947F
FF4FF4A70986D68ADAC0EB3E500000000049454E44AE426082}
LoadImage = 'C:\Program Files\eDocfile\File One\Images\menubackground.png'
end
object msButton1: tMSButton
Left = 15
Top = 106
Width = 320
Height = 30
Caption = 'Run Program'
DoubleBuffered = True
ParentDoubleBuffered = False
ParentShowHint = False
ShowHint = False
TabOrder = 0
DoBrowse = False
BrowseStyle = fbOpen
end
object msButton2: tMSButton
Left = 15
Top = 166
Width = 161
Height = 30
Caption = 'Setup Rules'
DoubleBuffered = True
ModalResult = 3
ParentDoubleBuffered = False
ParentShowHint = False
ShowHint = False
TabOrder = 1
DoBrowse = False
BrowseStyle = fbOpen
end
object msButton4: tMSButton
Left = 15
Top = 195
Width = 161
Height = 30
Caption = 'Help'
DoubleBuffered = True
ModalResult = 5
ParentDoubleBuffered = False
ParentShowHint = False
ShowHint = False
TabOrder = 2
DoBrowse = False
BrowseStyle = fbOpen
end
object msButton5: tMSButton
Left = 175
Top = 166
Width = 161
Height = 30
Caption = 'Manually Process'
DoubleBuffered = True
ModalResult = 7
ParentDoubleBuffered = False
ParentShowHint = False
ShowHint = False
TabOrder = 3
DoBrowse = False
BrowseStyle = fbOpen
end
object msButton6: tMSButton
Left = 175
Top = 195
Width = 161
Height = 30
Caption = 'Exit'
DoubleBuffered = True
ModalResult = 2
ParentDoubleBuffered = False
ParentShowHint = False
ShowHint = False
TabOrder = 4
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1


VBEval>IsProcessRunning("File_One_Processing.exe"),res
If>res>0
GoSub>RunningSub
Else
GoSub>NotRunningSub
Endif

SRT>RunningSub
SetDialogProperty>Dialog1,MSBUTTON1,Caption,Shut Down Program
END>RunningSub

SRT>NotRunningSub
SetDialogProperty>Dialog1,MSBUTTON1,Caption,Run Program
END>NotRunningSub

SetDialogProperty>Dialog1,,Caption,Registered to %License%
AddDialogHandler>Dialog1,MSButton1,OnClick,Runit

Show>Dialog1,r
If>r=2,EOF
If>r=3,setuprules
If>r=5,Displayhelp
If>r=7,ManuallyProcess


SRT>Runit
VBEval>IsProcessRunning("File_One_Processing.exe"),res
If>res>0
VBRun>KillProcess,File_One_Processing.exe
VBEval>IsProcessRunning("File_One_Processing.exe"),res
If>res>0
MDL>The monitor function cannot be shutdown. It could be in use by another user.
Endif

GoSub>NotRunningSub
Goto>reset
Endif
ChangeDirectory>%ProgramFolder%
Let>RP_WAIT=0
Let>RP_WINDOWMODE=0
RunProgram>"File_One_Processing.exe"
Exit>0
Label>reset
End>Runit


Label>Shutdown
ChangeDirectory>%ProgramFolder%
Let>RP_WAIT=0
Let>RP_WINDOWMODE=0
RunProgram>"File_One_Processing.exe"
Goto>EOF



Label>setuprules
ResetDialogAction>Dialog1
ChangeDirectory>%ProgramFolder%
Let>RP_WAIT=0
Let>RP_WINDOWMODE=1
RunProgram>"Setup File One.exe"
Goto>EOF


SRT>Displayhelp
ChangeDirectory>%ProgramFolder%
ResetDialogAction>Dialog1
Let>RP_WAIT=0
Let>RP_WINDOWMODE=3
RunProgram>hh.exe -mapid 10 ms-its:%ProgramFolder%\File One Help.chm
END>Displayhelp

Label>ManuallyProcess
ChangeDirectory>%ProgramFolder%
Let>RP_WAIT=0
Let>RP_WINDOWMODE=1
RunProgram>"RunManualIndexer.exe"
Goto>EOF

Label>EOF
Exit>0

[/code]

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Only after the Dialog

Post by kpassaur » Thu Jun 03, 2010 11:23 am

I did some more testing and it appears that no VBScript works after the dialog.

Since I could not get is processing runnning to work I changed it to getting the button text. This actually made it simpler. However, when I go to kill the process it does not kill it. So, I moved the line above the dialog and left the process runninig. When it loads it kills the process so, something in the Dialog appears to be stopping VBScript from running.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jun 03, 2010 12:32 pm

Hmmm .. an oversight in the documentation (or implementation - whichever way you want to look at it) is that for dialog handlers the vbscript needs to be local. If you put a VBSTART/VBEND block inside your handler subroutine with the VBScript function you want to call you will find it works.

We'll look at whether this can/should be changed implementation-or-documentation-wise in future.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

VBScript in Dialog Handler

Post by kpassaur » Thu Jun 03, 2010 4:39 pm

So the easy way would be to put the VBScript Block in a Subroutine and then just call all of it each time. In the past I always put it at the begining of the script.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jun 03, 2010 4:39 pm

No need. It's fixed in 12.0.1. See my last post in Announcements.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts