Jump to content
Sign in to follow this  
icemanV

Using Command prompt to start batch file

Recommended Posts

icemanV

My intention is to create a folder with all the shortcuts to their batch file. I have created a search for the filename and is able to identify the list of files in the folder.

However, the problem is when i try to use the run command to execute the DOS command prompt. I cannot seem to input the shortcuts filename into DOS command prompt. Any idea how I can use the DOS to execute the shortcuts or any other methods?

Thanks

Share this post


Link to post
Share on other sites
icemanV

Use Start with @ComSpec may suit your need

RunWait('"' & @ComSpec & '" /c start path\to\shortcut.lnk', '', @SW_HIDE)

:shocked:

The problem is i want the activate the shortcuts by the filename found. Which means I have shortcut A, shortcut B and shortcut C in the folder. I have to click once and it activate shortcut A, shortcut B and shortcut C.

Which means RunWait(""& @ComSpec & "/c start path\to" filename', '',@SW_HIDE)

filename cannot be hardcoded, it has to be a variable. Somehow, RunWait does not take in the filename.

Any idea how i can have a variable in this function RunWait????

Thanks

Share this post


Link to post
Share on other sites
MHz

Actually, Start is not needed for shortcuts so the quote issue for title is not a problem without using it.

Example with using variables.

$a = @ScriptDir & '\test\a.lnk'
$b = @ScriptDir & '\test\b.lnk'
$c = @ScriptDir & '\test\c.lnk'
DirCreate(@ScriptDir & '\test')
FileCreateShortcut('explorer.exe', $a)
FileCreateShortcut('explorer.exe', $B)
FileCreateShortcut('explorer.exe', $c)
RunWait('"' & @ComSpec & '" /c "' & $a & '"', '', @SW_HIDE)
RunWait('"' & @ComSpec & '" /c "' & $b & '"', '', @SW_HIDE)
RunWait('"' & @ComSpec & '" /c "' & $c & '"', '', @SW_HIDE)
DirRemove(@ScriptDir & '\test', 1)

Share this post


Link to post
Share on other sites
icemanV

Actually, Start is not needed for shortcuts so the quote issue for title is not a problem without using it.

Example with using variables.

$a = @ScriptDir & '\test\a.lnk'
$b = @ScriptDir & '\test\b.lnk'
$c = @ScriptDir & '\test\c.lnk'
DirCreate(@ScriptDir & '\test')
FileCreateShortcut('explorer.exe', $a)
FileCreateShortcut('explorer.exe', $B)
FileCreateShortcut('explorer.exe', $c)
RunWait('"' & @ComSpec & '" /c "' & $a & '"', '', @SW_HIDE)
RunWait('"' & @ComSpec & '" /c "' & $b & '"', '', @SW_HIDE)
RunWait('"' & @ComSpec & '" /c "' & $c & '"', '', @SW_HIDE)
DirRemove(@ScriptDir & '\test', 1)
Hi

I tried to change my code to use your logic but i get this error.

RunWait('"' & @ComSpec & '" /p"' & $tempScriptName & '""' & '@echo. && pause', @SW_HIDE)

The directory name is invalid.

This is my code

Dim $filename

Dim $exeName

Dim $tempScriptName

fileChangeDir("P:\LINKS\chieht\Start_All")

MsgBox(0, "Directory: ", @WorkingDir)

Dim $search = FileFindFirstFile(@WorkingDir & "\*.lnk")

While $search = 1

MsgBox(4096, "File :", $filename)

$tempScriptName = @WorkingDir & '\' & $filename

MsgBox(0, "script dir :", $tempScriptName)

if StringIsAlpha($filename) == 1 Then

MsgBox(0, "file1 : ", $filename)

ElseIf $filename == "" Then

MsgBox(0, "file 2 : ", $filename)

Else

RunWait('"' & @ComSpec & '" /p"' & $tempScriptName & '""' & '@echo. && pause', @SW_HIDE)

EndIf

$filename = FileFindNextFile($search)

If @error Then ExitLoop

WEnd

This is just the testing phase for me, hence the if debug statement. Any idea what did i do wrong? i wish they have a book that describe this tool.

Thanks

Share this post


Link to post
Share on other sites
SadBunny

RunWait('"' & @ComSpec & '" /p"' & $tempScriptName & '""' & '@echo. && pause', @SW_HIDE)

The directory name is invalid.

It seems you forgot to place a space between the " /p" and the $tempScriptName, leading to /pmyscript instead of /p myscript. Try '" /p "' instead (space between p and quote). Keep this in mind for the rest of the line too, like with the @echo. String concatenations do NOT intrudoce spaces, you have to enter them yourself :shocked:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
MHz

Perhaps this is what you want?

Global $filename, $exeName, $tempScriptName
FileChangeDir("P:\LINKS\chieht\Start_All")
MsgBox(0, "Directory: ", @WorkingDir)

Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk")
If $search <> -1 Then
    While 1
        $filename = FileFindNextFile($search)
        If @error Then ExitLoop
        MsgBox(4096, "File :", $filename)

        $tempScriptName = @WorkingDir & '\' & $filename
        MsgBox(0, "script dir :", $tempScriptName)

        If StringIsAlpha($filename) Then
            MsgBox(0, "file1 : ", $filename)
        ElseIf $filename = "" Then
            MsgBox(0, "file2 : ", $filename)
        Else
            RunWait('"' & @ComSpec & '" /c "' & $tempScriptName & '"', @SW_HIDE)
        EndIf
    WEnd
    FileClose($search)
EndIf

If you want to see what @ComSpec is doing then change the @SW_HIDE parameter to @SW_SHOW and use the /k switch instead of /c.

Edit:

Added FileClose() to close the handle.

Edited by MHz

Share this post


Link to post
Share on other sites
icemanV

Perhaps this is what you want?

Global $filename, $exeName, $tempScriptName
FileChangeDir("P:\LINKS\chieht\Start_All")
MsgBox(0, "Directory: ", @WorkingDir)

Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk")
If $search <> -1 Then
    While 1
        $filename = FileFindNextFile($search)
        If @error Then ExitLoop
        MsgBox(4096, "File :", $filename)

        $tempScriptName = @WorkingDir & '\' & $filename
        MsgBox(0, "script dir :", $tempScriptName)

        If StringIsAlpha($filename) Then
            MsgBox(0, "file1 : ", $filename)
        ElseIf $filename = "" Then
            MsgBox(0, "file2 : ", $filename)
        Else
            RunWait('"' & @ComSpec & '" /c "' & $tempScriptName & '"', @SW_HIDE)
        EndIf
    WEnd
    FileClose($search)
EndIf

If you want to see what @ComSpec is doing then change the @SW_HIDE parameter to @SW_SHOW and use the /k switch instead of /c.

Edit:

Added FileClose() to close the handle.

I have tried your code I still get the same error message. I left the space between '" /k "' & $tempScriptName ... but still get the same error. Is it possible that runwait does not take in $tempScriptName

Thanks

Share this post


Link to post
Share on other sites
SadBunny

I have tried your code I still get the same error message. I left the space between '" /k "' & $tempScriptName ... but still get the same error. Is it possible that runwait does not take in $tempScriptName

Thanks

Just for debugging purposes, let a msgbox show the complete string that you are trying to run with the Run() command, to see what exactly is the string. And have it placed on the clipboard, by ClipPut(), so you can post it here.

It's very possible that you are overlooking something in creating the commandline string for the Run command, so looking at the string that's actually created for the Run command might clear up possible oversights of this sort.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
BrettF

Just for debugging purposes, let a msgbox show the complete string that you are trying to run with the Run() command, to see what exactly is the string. And have it placed on the clipboard, by ClipPut(), so you can post it here.

It's very possible that you are overlooking something in creating the commandline string for the Run command, so looking at the string that's actually created for the Run command might clear up possible oversights of this sort.

Like this:

Global $filename, $exeName, $tempScriptName
FileChangeDir("P:\LINKS\chieht\Start_All")
MsgBox(0, "Directory: ", @WorkingDir)

Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk")
If $search <> -1 Then
    While 1
        $filename = FileFindNextFile($search)
        If @error Then ExitLoop
        MsgBox(4096, "File :", $filename)

        $tempScriptName = @WorkingDir & '\' & $filename
        MsgBox(0, "script dir :", $tempScriptName)

        If StringIsAlpha($filename) Then
            MsgBox(0, "file1 : ", $filename)
        ElseIf $filename = "" Then
            MsgBox(0, "file2 : ", $filename)
        Else
            ClipPut($tempScriptName)
        EndIf
    WEnd
    FileClose($search)
EndIf

Share this post


Link to post
Share on other sites
MHz

Let's try a different way to solve this.

Try this.

Global $filename, $exeName, $tempScriptName
FileChangeDir("P:\LINKS\chieht\Start_All")
MsgBox(0, "Directory: ", @WorkingDir)

Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk")
If $search <> -1 Then
    While 1
        $filename = FileFindNextFile($search)
        If @error Then ExitLoop
        MsgBox(4096, "File :", $filename)

        $tempScriptName = @WorkingDir & '\' & $filename
        MsgBox(0, "script dir :", $tempScriptName)

        If StringIsAlpha($filename) Then
            MsgBox(0, "file1 : ", $filename)
        ElseIf $filename = "" Then
            MsgBox(0, "file2 : ", $filename)
        Else
            $parameter = FileGetShortcut($tempScriptName)
            If Not @error Then
                MsgBox(0, 'debug', '"' & $parameter[0] & '" ' & $parameter[2] & ', ' & $parameter[1])
                RunWait('"' & $parameter[0] & '" ' & $parameter[2], $parameter[1])
            EndIf
        EndIf
    WEnd
    FileClose($search)
EndIf

Share this post


Link to post
Share on other sites
icemanV

Hi

I did what you said. The string looks good. "P:\LINKS\chieht\Start_All\REX.lnk". Then I tried the using the actual string on the commmand RunWait('"' & @ComSpec & '" /k "' & '"P:\LINKS\chieht\Start_All\REX"' & '"', @SW_SHOW). I still get the error directory name is invalid.

Is my syntax correct?

Share this post


Link to post
Share on other sites
icemanV

Let's try a different way to solve this.

Try this.

Global $filename, $exeName, $tempScriptName
FileChangeDir("P:\LINKS\chieht\Start_All")
MsgBox(0, "Directory: ", @WorkingDir)

Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk")
If $search <> -1 Then
    While 1
        $filename = FileFindNextFile($search)
        If @error Then ExitLoop
        MsgBox(4096, "File :", $filename)

        $tempScriptName = @WorkingDir & '\' & $filename
        MsgBox(0, "script dir :", $tempScriptName)

        If StringIsAlpha($filename) Then
            MsgBox(0, "file1 : ", $filename)
        ElseIf $filename = "" Then
            MsgBox(0, "file2 : ", $filename)
        Else
            $parameter = FileGetShortcut($tempScriptName)
            If Not @error Then
                MsgBox(0, 'debug', '"' & $parameter[0] & '" ' & $parameter[2] & ', ' & $parameter[1])
                RunWait('"' & $parameter[0] & '" ' & $parameter[2], $parameter[1])
            EndIf
        EndIf
    WEnd
    FileClose($search)
EndIf
I tried your set of codes it worked!!! Thanks. What I don't understand where did you get your variable $parameter. I did not see you declaring the array anyway. Please share...=)

Thanks people

Share this post


Link to post
Share on other sites
MHz

I tried your set of codes it worked!!! Thanks. What I don't understand where did you get your variable $parameter. I did not see you declaring the array anyway. Please share...=)

Thanks people

FileGetShortcut() creates the array. An example is in the help file for more on FileGetShortcut(). $parameter is created in the same line as FileGetShortcut(). I am not use MustDeclareVar settings, so assigning a variable is as valid as declaring a variable to initialize it.

:shocked:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.