Building a Command in a Function

I'll skip the disclaimers about not being a programming whiz, and plead for some help.

The task is to write a function for a button that will run a script file with some command modifiers thrown in. If I'm understanding the scripting environment correctly, I need to create a Command object and build the lines that I would enter in the Advanced button function. (The entire project needs to display a dialog box with notice to the user that the command is running, then destroy the dialog when the command completes). I can't seem to find a good example of how to create the command in vbs and have come up with this:

[code]@script vbscript

Function OnClick(ByRef ClickData)

Set cmd = DOpus.NewCommand()
cmd.AddLine = "@admin"
cmd.AddLine = "@runmode:hide"
cmd.AddLine = "@sync:cmd /c " & Chr(34) & "C:\Users\User\Documents\Scripts\FixTempFolder\FixTempFolder.cmd" & Chr(34)

Set dlg = ClickData.func.dlg
    dlg.message = "Resetting permissions . . ."      
dlg.buttons = "WAIT"
dlg.title = "Reset Temp Folder Permissions"
dlg.icon = "warn"
ret = dlg.Show

cmd.Run

End Function[/code]

It's obvious that I'm missing several boats with the code above - even to me! When I run this, nothing happens. If I comment out all of the command section, the dialog box works fine. One other thing that has me stumped is whether I can create a message box that has no buttons and can be destroyed programmatically. The Windows command file resets folder inherited permissions on my temp files folder. The time the system takes to do this depends on how many files are in the folder, so I want to display the dialog while the process is executing, then close.

Any help is appreciated.

I think this

cmd.AddLine = "@runmode:hide"

should be done like this. (note js)

cmd.SetModifier("runmode", "hide"); 

Perhaps both methods work, but that is now I did it in this script where I was executing an external resource.

As for the message box, this might help Stackoverflow link

[code]set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActive "your message here"

'do some work, run you dopus command here

'send command to message box to close it
WshShell.SendKeys "%N"[/code]

I didnt test this :s

Opus provides an object for controlling its progress dialog which is probably more suitable for showing a message while an operation is happening.

(Always good to avoid using SendKeys, too.)

I was not aware of that feature existed. nice

You may try this button from here:

It incorporates a simple process dialog you probably can use as an example.

Thanks. I'm still having problems with building the command. I extracted the code and began working with it in the CLI interpreter, where I can get error messages. When I run the lines:

    Set cmd = DOpus.NewCommand
    
    cmd.AddLine = "@sync:cmd /c " & Chr(34) & "C:\Users\David\Documents\Scripts\FixTempFolder\FixTempFolder.cmd" & Chr(34)
    'cmd.SetModifier = "runmode hide"

I get Error at line 3, position 5
A method was called unexpectedly (0x8000ffff)

Can anyone see what's wrong with this?

Remove the = after cmd.Addline and I think it will work.

Did not use SetModifier() myself yet, but the syntax is probably more like this (as shown above):

cmd.SetModifier("runmode", "hide");

You need to pay attention to these brackets, commas etc., the code won't run otherwise.

Ooops! Forget about my post, you use vbscript instead of jscript but I noticed to late. o)

Yes. I now have the code running :slight_smile: (Thanks, Leo, for seeing my "=" in the method). The vbs version is:

cmd.SetModifier "runmode","hide"

Now working on the progress bar.