Announcement

Collapse
No announcement yet.

help with command line options

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help with command line options

    Hi,

    I need to find if there are any substituted drive on the machine.
    Unfortunately the Drive.Enumerate function doesn’t display the substituted drive. Hence i am using the command line option to retrieve the same.
    I ran the below command, but the result is nil, if i run the same file manually its working fine. Can anyone help me out?
    I even tried the commandline plugin, but in vain.

    Code:
    TextFile.WriteFromString(_TempFolder .. "\\Information.bat", "subst > outputs.txt", false);
     --File.Run(_TempFolder .. "\\Information.bat", " ", _TempFolder,SW_SHOWNORMAL,true);
    File.Run(_SystemFolder.."\\cmd.exe", "/C "  .. _TempFolder .. "\\Information.bat ", "", SW_HIDE, true);
    text_contents = TextFile.ReadToTable (_TempFolder .. "\\outputs.txt");

  • #2
    Try this:

    WinCMD.zip

    you wont need to bother with having files and running them.

    Comment


    • #3
      hi Shrek,

      Thanks for the code. Its working as in your project, but when i tried to use in my project, its not working. I am not getting the output, can you see what is wrong with the code below? If i use different command like "hostname" it works fine. But for "subst" it is not working.

      Code:
      tbinput = "subst";
      WinCmd.Input(tbinput);
      output = WinCmd.Output();
      error = WinCmd.Error();
      newout = String.Length (output);
      
      if (error == "") then
      	Dialog.Message("output", "output is " .. output);
      	Dialog.Message("Length", "String length is " .. newout);
      else
      	Dialog.Message("Table Item error", "error");
      	Dialog.Message("Error!!", "Error is " .. error);
      end

      Comment


      • #4
        Code:
        [COLOR="#008000"]-- Global[/COLOR]
        WINCMD [COLOR="#FF0000"]={}[/COLOR]
        [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Input(cmd)
          DLL[COLOR="#FF0000"].[/COLOR]CallFunction([COLOR="#800080"]"AutoPlay[COLOR="#800080"]\\[/COLOR]Docs[COLOR="#800080"]\\[/COLOR]WinCmd.dll"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"Input"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"[COLOR="#800080"]\"[/COLOR]"[/COLOR][COLOR="#FF0000"]..[/COLOR]cmd[COLOR="#FF0000"]..[/COLOR][COLOR="#800080"]"[COLOR="#800080"]\"[/COLOR]"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]1[/COLOR])
        [COLOR="#0000FF"]end[/COLOR]
        [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Output()
          [COLOR="#0000FF"]return[/COLOR] DLL[COLOR="#FF0000"].[/COLOR]CallFunction([COLOR="#800080"]"AutoPlay[COLOR="#800080"]\\[/COLOR]Docs[COLOR="#800080"]\\[/COLOR]WinCmd.dll"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"Output"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]""[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]2[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]1[/COLOR])
        [COLOR="#0000FF"]end[/COLOR]
        [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Error()
          [COLOR="#0000FF"]return[/COLOR] DLL[COLOR="#FF0000"].[/COLOR]CallFunction([COLOR="#800080"]"AutoPlay[COLOR="#800080"]\\[/COLOR]Docs[COLOR="#800080"]\\[/COLOR]WinCmd.dll"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"Error"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]""[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]2[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]1[/COLOR])
        [COLOR="#0000FF"]end[/COLOR]
        [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Trim(s)
          [COLOR="#0000FF"]return[/COLOR] (s:[COLOR="#0000FF"]gsub[/COLOR]([COLOR="#800080"]"^%s*(.-)%s*$"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"%1"[/COLOR]))
        [COLOR="#0000FF"]end[/COLOR]
        [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]CallTable(cmd)
         WINCMD[COLOR="#FF0000"].[/COLOR]Input(cmd)
         [COLOR="#0000FF"]local[/COLOR] R [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Output()
         [COLOR="#0000FF"]local[/COLOR] E [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Error()
         [COLOR="#0000FF"]if[/COLOR] (E [COLOR="#FF0000"]==[/COLOR] [COLOR="#800080"]""[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
          [COLOR="#0000FF"]local[/COLOR] Tmp [COLOR="#FF0000"]=[/COLOR] [COLOR="#FF0000"]{}[/COLOR]
          [COLOR="#0000FF"]for[/COLOR] CMDline [COLOR="#0000FF"]in[/COLOR] [COLOR="#0000FF"]string.gfind[/COLOR] (R[COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"[^[COLOR="#800080"]\n[/COLOR]]+"[/COLOR]) [COLOR="#0000FF"]do[/COLOR]
           CMDline [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Trim(CMDline)
           [COLOR="#0000FF"]table.insert[/COLOR](Tmp[COLOR="#FF0000"],[/COLOR]CMDline)
          [COLOR="#0000FF"]end[/COLOR]
           [COLOR="#0000FF"]return[/COLOR] Tmp
         [COLOR="#0000FF"]else[/COLOR]
           [COLOR="#0000FF"]return[/COLOR] Tmp
         [COLOR="#0000FF"]end[/COLOR]
        [COLOR="#0000FF"]end[/COLOR]
        [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]CallString(cmd)
         WINCMD[COLOR="#FF0000"].[/COLOR]Input(cmd)
         [COLOR="#0000FF"]local[/COLOR] R [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Output()
         [COLOR="#0000FF"]local[/COLOR] E [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Error()
         [COLOR="#0000FF"]if[/COLOR] (E [COLOR="#FF0000"]==[/COLOR] [COLOR="#800080"]""[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
           [COLOR="#0000FF"]return[/COLOR] R
          [COLOR="#0000FF"]else[/COLOR]
           [COLOR="#0000FF"]return[/COLOR] E
         [COLOR="#0000FF"]end[/COLOR]
        [COLOR="#0000FF"]end[/COLOR]
        
        [COLOR="#008000"]--On Button Click[/COLOR]
        
          [COLOR="#008000"]--Get result as a table[/COLOR]
          [COLOR="#0000FF"]local[/COLOR] A [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]CallTable([COLOR="#800080"]"ipconfig /release"[/COLOR])
          [COLOR="#0000FF"]local[/COLOR] Err [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Error()
          [COLOR="#0000FF"]if[/COLOR] (Err [COLOR="#FF0000"]~=[/COLOR] [COLOR="#0000FF"]nil[/COLOR] ) [COLOR="#0000FF"]then[/COLOR]
            [COLOR="#0000FF"]for[/COLOR] i[COLOR="#FF0000"],[/COLOR]v [COLOR="#0000FF"]in[/COLOR] [COLOR="#0000FF"]pairs[/COLOR](A)[COLOR="#0000FF"]do[/COLOR]
              Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"CMD (A)"[/COLOR][COLOR="#FF0000"],[/COLOR]v)
            [COLOR="#0000FF"]end[/COLOR]
          [COLOR="#0000FF"]else[/COLOR]
            Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"CMD (A)"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"Error"[/COLOR])
          [COLOR="#0000FF"]end[/COLOR]
        
          [COLOR="#008000"]--Get result as a string[/COLOR]
          [COLOR="#0000FF"]local[/COLOR] B [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]CallString([COLOR="#800080"]"ipconfig /renew"[/COLOR])
          [COLOR="#0000FF"]local[/COLOR] Err [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Error()
          [COLOR="#0000FF"]if[/COLOR] (Err [COLOR="#FF0000"]~=[/COLOR] [COLOR="#0000FF"]nil[/COLOR] ) [COLOR="#0000FF"]then[/COLOR]
            Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"CMD (B)"[/COLOR][COLOR="#FF0000"],[/COLOR]B)
          [COLOR="#0000FF"]else[/COLOR]
           Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"CMD (B)"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"Error"[/COLOR])
          [COLOR="#0000FF"]end[/COLOR]

        Try that, on XP you get erratic spacing in the output so using the table method fixes that.

        Comment


        • #5
          Code:
          [COLOR="#008000"]-- Global[/COLOR]
          WINCMD [COLOR="#FF0000"]={}[/COLOR]
          [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Input(cmd)
            DLL[COLOR="#FF0000"].[/COLOR]CallFunction([COLOR="#800080"]"AutoPlay[COLOR="#800080"]\\[/COLOR]Docs[COLOR="#800080"]\\[/COLOR]WinCmd.dll"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"Input"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"[COLOR="#800080"]\"[/COLOR]"[/COLOR][COLOR="#FF0000"]..[/COLOR]cmd[COLOR="#FF0000"]..[/COLOR][COLOR="#800080"]"[COLOR="#800080"]\"[/COLOR]"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]1[/COLOR])
          [COLOR="#0000FF"]end[/COLOR]
          [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Output()
            [COLOR="#0000FF"]return[/COLOR] DLL[COLOR="#FF0000"].[/COLOR]CallFunction([COLOR="#800080"]"AutoPlay[COLOR="#800080"]\\[/COLOR]Docs[COLOR="#800080"]\\[/COLOR]WinCmd.dll"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"Output"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]""[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]2[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]1[/COLOR])
          [COLOR="#0000FF"]end[/COLOR]
          [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Error()
            [COLOR="#0000FF"]return[/COLOR] DLL[COLOR="#FF0000"].[/COLOR]CallFunction([COLOR="#800080"]"AutoPlay[COLOR="#800080"]\\[/COLOR]Docs[COLOR="#800080"]\\[/COLOR]WinCmd.dll"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"Error"[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#800080"]""[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]2[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]1[/COLOR])
          [COLOR="#0000FF"]end[/COLOR]
          [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]CallTable(cmd)
           WINCMD[COLOR="#FF0000"].[/COLOR]Input(cmd)
           [COLOR="#0000FF"]local[/COLOR] R [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Output()
           [COLOR="#0000FF"]local[/COLOR] E [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Error()
           [COLOR="#0000FF"]local[/COLOR] Tmp [COLOR="#FF0000"]=[/COLOR] [COLOR="#FF0000"]{}[/COLOR]
           [COLOR="#0000FF"]if[/COLOR] (E [COLOR="#FF0000"]==[/COLOR] [COLOR="#800080"]""[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
            [COLOR="#0000FF"]for[/COLOR] CMDline [COLOR="#0000FF"]in[/COLOR] [COLOR="#0000FF"]string.gfind[/COLOR] (R[COLOR="#FF0000"],[/COLOR][COLOR="#800080"]"[^[COLOR="#800080"]\n[/COLOR]]+"[/COLOR]) [COLOR="#0000FF"]do[/COLOR]
             CMDline [COLOR="#FF0000"]=[/COLOR] CMDline:[COLOR="#0000FF"]gsub[/COLOR]([COLOR="#800080"]"^%s*(.-)%s*$"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"%1"[/COLOR])
             [COLOR="#0000FF"]table.insert[/COLOR](Tmp[COLOR="#FF0000"],[/COLOR]CMDline)
            [COLOR="#0000FF"]end[/COLOR]
             [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]true[/COLOR][COLOR="#FF0000"],[/COLOR] Tmp
           [COLOR="#0000FF"]else[/COLOR]
             [COLOR="#0000FF"]table.insert[/COLOR](Tmp[COLOR="#FF0000"],[/COLOR]E)
             [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]false[/COLOR][COLOR="#FF0000"],[/COLOR] Tmp
           [COLOR="#0000FF"]end[/COLOR]
          [COLOR="#0000FF"]end[/COLOR]
          [COLOR="#0000FF"]function[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]CallString(cmd)
           WINCMD[COLOR="#FF0000"].[/COLOR]Input(cmd)
           [COLOR="#0000FF"]local[/COLOR] R [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Output()
           [COLOR="#0000FF"]local[/COLOR] E [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]Error()
           [COLOR="#0000FF"]if[/COLOR] (E [COLOR="#FF0000"]==[/COLOR] [COLOR="#800080"]""[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
             [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]true[/COLOR][COLOR="#FF0000"],[/COLOR] R
            [COLOR="#0000FF"]else[/COLOR]
             [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]false[/COLOR][COLOR="#FF0000"],[/COLOR] E
           [COLOR="#0000FF"]end[/COLOR]
          [COLOR="#0000FF"]end[/COLOR]
          
          [COLOR="#008000"]--On Button Click[/COLOR]
          
            [COLOR="#008000"]--Get result as a table[/COLOR]
            [COLOR="#0000FF"]local[/COLOR] _[COLOR="#FF0000"],[/COLOR] A [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]CallTable([COLOR="#800080"]"ipconfig /release"[/COLOR])
            [COLOR="#0000FF"]if[/COLOR] _ [COLOR="#0000FF"]then[/COLOR]
              [COLOR="#0000FF"]for[/COLOR] i[COLOR="#FF0000"],[/COLOR]v [COLOR="#0000FF"]in[/COLOR] [COLOR="#0000FF"]pairs[/COLOR](A)[COLOR="#0000FF"]do[/COLOR]
                Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"CMD (A)"[/COLOR][COLOR="#FF0000"],[/COLOR]v)
              [COLOR="#0000FF"]end[/COLOR]
            [COLOR="#0000FF"]else[/COLOR]
              Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"CMD (A)"[/COLOR][COLOR="#FF0000"],[/COLOR]A[COLOR="#FF0000"][[/COLOR][COLOR="#000000"]1[/COLOR][COLOR="#FF0000"]][/COLOR])
            [COLOR="#0000FF"]end[/COLOR]
          
            [COLOR="#008000"]--Get result as a string[/COLOR]
            [COLOR="#0000FF"]local[/COLOR] _[COLOR="#FF0000"],[/COLOR] B [COLOR="#FF0000"]=[/COLOR] WINCMD[COLOR="#FF0000"].[/COLOR]CallString([COLOR="#800080"]"ipconfig /renew"[/COLOR])
            [COLOR="#0000FF"]if[/COLOR] _ [COLOR="#0000FF"]then[/COLOR]
              Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"CMD (B)"[/COLOR][COLOR="#FF0000"],[/COLOR]B)
            [COLOR="#0000FF"]else[/COLOR]
              Dialog[COLOR="#FF0000"].[/COLOR]Message([COLOR="#800080"]"CMD (B)"[/COLOR][COLOR="#FF0000"],[/COLOR]B)
            [COLOR="#0000FF"]end[/COLOR]
          that even.

          Comment


          • #6
            Thanks Shrek for the code.

            Unfortunately both the code returns empty string. I am not sure if i am missing something in here. I even tried to run it as an administrator, looks like its more to do with the "subst" command the way its ran. Because as i mentioned initially, the batch script works fine outside but not thru autoplay.

            Comment


            • #7
              Says here that in Windows 2000 (and above) you may have problems creating, accessing and deleting drive mappings with SUBST. However under Win 2K/XP the functionality of the NET USE command is improved so you can now do NET USE g: \\server\share\folder1\folder2

              Comment


              • #8
                Thanks for the infor shrek, but the same work fine from your project, the button click displays perfect. but not from my project though. I cant use net command, as i just want to know if a specified drive is in use or not. net command doesnt diplay drives that are substitutted.

                Comment


                • #9
                  this code can't run on windows 10. any solution?

                  Comment

                  Working...
                  X