Forum Discussion

m_essaid's avatar
m_essaid
Valued Contributor
7 years ago

net use

Hi,

 

Does anyone has an idea how could I use the "net use" command within a script ?

 

For example, I do :

 

  TestedApps.Clear;
  TestedApps.Add('cmd.exe', '/c net use N: /d /y', 1, true, '');
  TestedApps.cmd.Run;

 

And I do the same for adding the N: drive. But it do nothing.

 

I'm launching TestExecute during the night with a schedulled task that runs a .BAT.

 

Any help would be much appreciated, I can't figure out how to make it run as if it was with admin privileges.

 

Mehdi

7 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    I used my net commands like below

     

    Sys.OleObject("WScript.Shell").Exec("cmd /c net start myserviceName");

    Maybe you can try the same. If you want to run as administrator then i guess it is enough to start the TestComplete as Administrator

    • shankar_r's avatar
      shankar_r
      Community Hero

      This link  might be helpful for you to frame your command to run as administrator scenario.

  • m_essaid's avatar
    m_essaid
    Valued Contributor

    Hey guys, thank you a lot for your help.

     

    Finaly I used this combination :

     

    a powershell script launches a .bat file in admin mode :

    Start-Process C:\filelocation.bat -Verb RunAs

     

    Then the .bat makes some copies (robocopy) and at the end launches TestExecute with admin privileges as it has been set with the ps1 script

     

    And at the end, I don't use the "net use" command but the build-in TestComplete commands :

     

      aqFileSystem.DisconnectNetworkDrive('n:', True, False);
      aqFileSystem.MapNetworkDrive('n:', '\\drivelocation',
        'domain\login', 'password', False);

  • m_essaid's avatar
    m_essaid
    Valued Contributor

    Hi there,

     

    As a matter of fact I have plenty of ways to do that now.

    But I didn't found any way to run TestExecute automaticaly in admin mode...

    What is the clue ? Let TestExecute open permanently so I would have to launch it manually once ?

    I have now 4 sets of Projects that runs the night on 4 VM. How to make TE run as admin ?

    I tried the Windows scheduller, it's a real pain. It just don't work with admin mode and .bat files.

     

    Until now, I don't have any clue.

     

    Mehdi

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi Mehdi,

       

      To execute some program with admin rights elevation from the Task Scheduler, consider PowerShell with the command like this:

      Program: powershell

      Arguments: -Command "Start-Process -FilePath 'regedit' -ArgumentList '/S myFile.reg' -Verb runAs"

       

      "-Verb runAs" is a key part of the command. Does it help?

    • shankar_r's avatar
      shankar_r
      Community Hero

      I guess you can try below steps,

       

      To mark an application to always run as an administrator, do the following: 
      1. On the Start menu, locate the program that you want to always run as an administrator. 
      2. Right-click the application’s shortcut, and then click Properties. 
      3. In the Properties dialog box, click the Compatibility tab. 
      4. Do one of the following: 

      • To apply the setting to the currently logged-on user, select the Run This Program As An Administrator check box, and then click OK.
      • To apply the setting to all users on the computer and regardless of which shortcut is used to start the application, click Change Setting For All Users to display the Properties dialog box for the application’s .exe file, select the Run This Program As An Administrator check box, and then click OK twice.

      Ref: https://technet.microsoft.com/en-us/library/ff431742.aspx