Announcement

Collapse
No announcement yet.

Code Check Please

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

  • Widget
    replied
    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);

    Leave a comment:


  • Widget
    replied
    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

    Leave a comment:


  • Widget
    replied
    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.

    Leave a comment:


  • mrdude
    replied
    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.

    Leave a comment:


  • Widget
    replied
    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

    Leave a comment:


  • Widget
    replied
    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

    Leave a comment:


  • Widget
    replied
    Batch file works fine.

    C:\TSAT>mapdrive.bat

    C:\TSAT>net use t: \\10.10.10.40\C$ /user:administrator "password"
    The command completed successfully.

    I now have a drive mapping. running the batch manually works every time. When calling it up through AMS it says the same results (Complete successfully) but does not map the drive. Double click the batch file and it work.

    I posted my project, can you change the code to reflect your user info to see if it works for you? Thanks

    Leave a comment:


  • mrdude
    replied
    Here's an example of some code I made ages ago - it only works if I invoke apms as administrator in the settings:

    Code:
    args = ' interface ipv4 set address "xxxxx" static 192.168.100.10 255.255.255.0 192.168.100.1 1';
    args2 = String.Replace(args, "xxxxx", lanname, false);
    --Shell.Execute("AutoPlay\\Docs\\netsh.exe", "open", args2, "AutoPlay\\Docs\\", false, true);
    File.Run(_SystemFolder .. "\\netsh.exe", args2, _SystemFolder, false, true);
    And doesn't work on windows xp - but works on everything upwards from that.

    Leave a comment:


  • mrdude
    replied
    Originally posted by Widget View Post
    using
    Code:
    File.RunAs("C:\\TSAT\\MapDrive.bat", "", "", SW_SHOWNORMAL, false, RunUID, RunPWD, "", LOGON_NO_OPTION, nil, nil);
    launch the batch file and says the command complete successfully, but no drive mapping was mapped. I did run autorun as admin.


    Not sure sure why this does not work. Seems fairly simple to do!?

    Is there away to save the batch file as IP from IP = Input.GetText("ip");? Example the batch file would be called MappedDrive_192.168.1.1.bat.

    Thanks
    Open a command prompt on your PC in the same location as your bat file: (go to the folder - hold shift/right click on your mouse - open command window here), then type the name of your bat file. You should see in the command window what it's doing, first thing is to make sure that your batch file is working properly.

    Leave a comment:


  • Widget
    replied
    Also, using the same account as I did for RunAs, I can manually click on the batch file and it does map the drive.

    Tried on Windows 7 and Windows 10 both have the same results.

    Leave a comment:


  • Widget
    replied
    using
    Code:
    File.RunAs("C:\\TSAT\\MapDrive.bat", "", "", SW_SHOWNORMAL, false, RunUID, RunPWD, "", LOGON_NO_OPTION, nil, nil);
    launch the batch file and says the command complete successfully, but no drive mapping was mapped. I did run autorun as admin.


    Not sure sure why this does not work. Seems fairly simple to do!?

    Is there away to save the batch file as IP from IP = Input.GetText("ip");? Example the batch file would be called MappedDrive_192.168.1.1.bat.

    Thanks

    Leave a comment:


  • mrdude
    replied
    I have admin rights on my pc as well - however that doesn't mean every program that runs on it does, you still need to tell the computer that you apms autorun.exe is allowed to run system32 files and make changes to other files - so you need to make the run as admin, like I said above.

    Just try it and if it works - you'll know what the problem is, if not???

    Leave a comment:


  • Widget
    replied
    mrdude,

    I tried using File.RunAs and that also fails. Using RunAs on other batch files works fine except for using net use.

    RunAs should work if using the correct account that has admin rights?

    Leave a comment:


  • mrdude
    replied
    Originally posted by Widget View Post
    mrdude,

    Tried using both sets of code but they return with "System Error 85" Which I think is a net use admin rights issue.
    I think if your program is trying to run a command from system32 such as cmd/net etc - you need to be admin for it to work. I have had this happen to me loads of time - for example if I want to call a batch file everything seems to work properly, but doesn't do anything - then I invoke as admin - then it works without any code changes.

    That's probably why you're having issues - although you can run a batch file manually - I think to test, you can go to your apms autorun.exe and right click on it - run as administrator. To check this.

    Leave a comment:


  • Widget
    replied
    mrdude,

    Tried using both sets of code but they return with "System Error 85" Which I think is a net use admin rights issue.

    Leave a comment:

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