Announcement

Collapse
No announcement yet.

Code Check Please

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

  • #16
    I have similar code for change IP info. That code works fine without running autorun.exe as admin. I just use the RunAs and it works fine. Same concept for mapping a drive! Below is the code I used for that.

    Code:
    RunUID = TextFile.ReadToString("AutoPlay\\Content\\Common\\CommonA.dat");
    RunPWD = TextFile.ReadToString("AutoPlay\\Content\\Common\\CommonP.dat");
    
    INT = Input.GetText("Interface1");
    qut = Input.GetText("qut");
    
    set = Input.SetText("ALL", "netsh interface ip show address " ..qut  ..INT ..qut.. " >c:\\TSAT\\GetIP.txt");
    get = Input.GetText("ALL");
    
    TextFile.WriteFromString("AutoPlay\\Docs\\SystemLog.txt", System.GetDate(DATE_FMT_US).." | "..System.GetTime(TIME_FMT_AMPM).." | Get Other IP of Interfaces was selected\r\n", true);
    -- Check to see if a specific folder exists.
    does_exist = Input.GetText(INT);
    
    if INT == "" then
    Dialog.Message("Notice", "Local Area Connection cannot be blank! Choose a connection from the Available Interfaces.", MB_OK, MB_ICONINFORMATION);
    elseif does_exist then
    
    TextFile.WriteFromString("C:\\TSAT\\GetIP.bat", get.. "", false);
    File.RunAs("C:\\TSAT\\GetIP.bat", "", "", SW_HIDE, false, RunUID, RunPWD, "", LOGON_NO_OPTION, nil, nil);
    uSelectedText = TextFile.ReadToString("C:\\Windows\\TSAT\\GetIP.txt");
    
    end
    
    if INT == "Interface" then
    Dialog.Message("Notice", "You cannot use Interface for Local Area Connection! Choose a connection from the Available Interfaces.", MB_OK, MB_ICONINFORMATION);
    elseif does_exist then
    
    TextFile.WriteFromString("C:\\TSAT\\GetIP.bat", get.. "", false);
    File.RunAs("C:\\TSAT\\GetIP.bat", "", "", SW_HIDE, false, RunUID, RunPWD, "", LOGON_NO_OPTION, nil, nil);
    uSelectedText = TextFile.ReadToString("C:\\Windows\\TSAT\\GetIP.txt");
    
    
    end

    Comment


    • #17
      Here code that Changes the IP that is similar to the drive mapping using RunAs. This code works and allows me to change the IP of a device using the correct admin account.


      Code:
      RunUID = TextFile.ReadToString("AutoPlay\\Content\\Common\\CommonA.dat");
      RunPWD = TextFile.ReadToString("AutoPlay\\Content\\Common\\CommonP.dat");
      
      INT = Input.GetText("Interface1");
      IP = Input.GetText("IP");
      SUB = Input.GetText("Subnet");
      Gate = Input.GetText("Gateway");
      qut = Input.GetText("qut");
      
      set = Input.SetText("ALL", "netsh interface ip set address " ..qut  ..INT ..qut.. " static " ..IP.." " ..SUB.." " ..Gate.."");
      --set = Input.SetText("ALL", "netsh interface ip set address " ..INT.." static " ..IP.." " ..SUB.." " ..Gate.."");
      get = Input.GetText("ALL");
      
      -- Check to see if a specific folder exists.
      does_exist = Input.GetText(INT);
      
      if INT == "" then
      Dialog.Message("Notice", "Local Area Connection cannot be blank! Choose a connection from the Available Interfaces.", MB_OK, MB_ICONINFORMATION);
      elseif does_exist then
      
      TextFile.WriteFromString("C:\\TSAT\\ChangeIP.bat", get.. "", false);
      File.RunAs("C:\\TSAT\\ChangeIP.bat", "", "", SW_HIDE, false, RunUID, RunPWD, "", LOGON_NO_OPTION, nil, nil);
      uSelectedText = TextFile.ReadToString("C:\\Windows\\TSAT\\ChangeIP.txt");
      --Input.SetText("Interface", uSelectedText);
      
      TextFile.WriteFromString("AutoPlay\\Docs\\SystemLog.txt", System.GetDate(DATE_FMT_US).." | "..System.GetTime(TIME_FMT_AMPM).." | Change IP was set to static\r\n", true);
      end
      
      if INT == "Interface" then
      Dialog.Message("Notice", "You cannot use Interface for Local Area Connection! Choose a connection from the Available Interfaces.", MB_OK, MB_ICONINFORMATION);
      elseif does_exist then
      
      TextFile.WriteFromString("C:\\TSAT\\ChangeIP.bat", get.. "", false);
      File.RunAs("C:\\TSAT\\ChangeIP.bat", "", "", SW_HIDE, false, RunUID, RunPWD, "", LOGON_NO_OPTION, nil, nil);
      uSelectedText = TextFile.ReadToString("C:\\Windows\\TSAT\\ChangeIP.txt");
      --Input.SetText("Interface", uSelectedText);
      
      TextFile.WriteFromString("AutoPlay\\Docs\\SystemLog.txt", System.GetDate(DATE_FMT_US).." | "..System.GetTime(TIME_FMT_AMPM).." | Change IP was set to static\r\n", true);
      end

      Comment


      • #18
        I don't have the time to check your code m8 - if your batch works fine, then it doesn't work in apms it's because of admin issues generally. Instead of running a batch read the entire batch as a string and tell apms to use cmd with the string from your batch as arguments.

        Comment


        • #19
          I'm not following the last post!
          Code:
          Instead of running a batch read the entire batch as a string and tell apms to use cmd with the string from your batch as arguments.

          Comment


          • #20
            Here are 2 screen shots. One is executing the map1.bat from apms and the other is the same batch manually run (double click). Both show as completed successfully, but only the manually run batch file maps the drive. Could this be a bug? Thanks
            Attached Files

            Comment


            • #21
              FYI - Using File.Open works but File.Run, RunAs, Shell Execute does not. Why would this be?

              Code:
              File.Open("C:\\TSAT\\mapdrive.bat", "", SW_SHOWNORMAL);

              Comment

              Working...
              X
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎