Page 1 of 2 12 LastLast
Results 1 to 5 of 8

Thread: How to 'Run as administrator' from Install Script

  1. #1
    Join Date
    Nov 2006
    Posts
    81

    Question How to 'Run as administrator' from Install Script

    I have an Installscript MSI project.

    We need to create web service extensions. In oder to do that on IIS7, we need to run appcmd commands from cmd.exe. cmd.exe should be 'run as administrator' for this to work.

    When I right click on cmd.exe and select 'run as administrator', and run appcmd commands, it works fine. I am trying to do this from Install Script.

    I tried launchappandwait as follows:

    svRunas = SystemFolder ^ "runas.exe";
    svCmd = SystemFolder ^ "cmd.exe";
    svCmdLine = " /u:Administrator /savecred " + "\"" + svCmd + " /C " + svWebExtCMD;
    nResult = LaunchAppAndWait(svRunas, svCmdLine, WAIT);

    where the string svWebExtCmd contains the appcmd command.

    This does create the extension but it prompts for the administrator password.

    Is there any way I can implement this without the need for the admin password?

    Any immediate help will be appreciated!

    Thanks!

  2. #2
    Join Date
    Nov 2006
    Posts
    81
    Could anybody please help me on this?

  3. #3
    Join Date
    Nov 2002
    Location
    Akron
    Posts
    325
    Do you require the person installing your software to be an administrator? I would think that if the user who is installing the software that has administrator privileges wouldn't need the switch in the CMD.

    As another idea, have you looked into using COM objects with IIS? I have been using COM objects to interface into IIS for years now. I have used it to set flags, Add/Delete virtual folders, Add/Delete Application Pools, set security, and a lot more by using COM. There are several examples on how to use COM objects to configure IIS. Here is a link. Now admittedly, I have only used these functions with IIS on Windows Server 2003 and below.

  4. #4
    Join Date
    Nov 2006
    Posts
    81
    Thanks for the reply!

    The user installing our product needs to have administrative privileges. But even that will not suffice to run appcmd commands. Even when I have administrative privileges, I need to do 'Run as administrator' for the command prompt for appcmd commands to work.

    Our code works on IIS versions below IIS 7.

    I am trying to use ShellExecute from Install Script. But I am getting the error 'File not found' I am not sure about the parameters.

    This is what I tried:

    svCmd = SystemFolder ^ "cmd.exe";
    svApp = " /C appcmd set config /section:isapiCgiRestriction /+\"[path='" + sWebmaintPath + "\\CGIBIN\\" + svMatchingFileName + "',description='Webmaint',allowed='True']\"";
    svDir = SystemFolder ^ "Inetsrv";
    UseDLL("Shell32.dll");
    nResult = ShellExecuteA(
    NULL,
    "runas", // Trick for requesting elevation, this is a verb not listed in the documentation above.
    svCmd,
    svApp, // params
    svDir, // directory
    SW_SHOWNORMAL);
    UnUseDLL("Shell32.dll");

    Does this look right?

  5. #5
    Join Date
    Nov 2002
    Location
    Akron
    Posts
    325
    Instead of using the ShellExecuteA, have you tried using Install Shield script function LaunchAppAndWait?

    Here is an example when I use CACLS to set folder security.

    Code:
    ///////////////////////////////////////////////////////////////////////////////
    //                                                                           //
    //                                                                           //
    //                                                                           //
    ///////////////////////////////////////////////////////////////////////////////
    function My_CACLS(strTargetDir, strUserName)
        STRING  strCommand;
        STRING  szCmdArgs;
    begin
        //cmd /c cacls "C:\Program Files\AIMWorX\Data\Cas\Test" /T /E /G Users:F >"C:\Program Files\AIMWorX\Data\Cas\cacls.log"      
        ///////////////////////////////////////////////////////////////////
        // This modifies the Permissions on the directory to allow Full  //
        // Control for local logged in users.                            //
        //      cacls "<Directory>" /T /E /G Users:F                     //
        // cacls "<Directory>" /T /E /G Users:F >"<Temp>\cacls.log"      //
        ///////////////////////////////////////////////////////////////////
        //My_AddToLog(szCmd + szCmdArgs);
        //LaunchAppAndWait(szCmd, szCmdArgs, WAIT);
    
        strCommand = WINSYSDIR ^ "cmd.exe";
        //strTargetDir = WINDIR ^ "Microsoft.NET\\Framework\\v1.1.4322\\Temporary ASP.NET Files";
        if strUserName != "" then
            szCmdArgs = "/c cacls \"" + strTargetDir +"\" /T /E /G "+ strUserName +":F ";
        else
            szCmdArgs = "/c cacls \"" + strTargetDir +"\" /T /E /G Users:F ";
        endif;
        
        My_RunCMDandLog(strCommand, szCmdArgs);
    end;
    
    ///////////////////////////////////////////////////////////////////////////////
    //                                                                           //
    //                                                                           //
    //                                                                           //
    ///////////////////////////////////////////////////////////////////////////////
    function My_RunCMDandLog(strCommand, strArguments)
        LIST    listTemp;
        NUMBER  nIndex;
        NUMBER  nSize;
        STRING  strValue;
        STRING  strLogFile;
        STRING  strTemp;
    begin
        strLogFile = "";
        if GetEnvVar("TEMP", strLogFile) < 0 then
            strLogFile = "C:\\";
        endif;
        strLogFile = strLogFile ^ "RunCMDandLog.log";
        
        strArguments = strArguments +">\""+ strLogFile +"\"";
        LaunchAppAndWait(strCommand, strArguments, WAIT);
    
        My_AddToLog("");
        My_AddToLog("Command  := \""+ strCommand   +"\"");
        My_AddToLog("Arguments:= \""+ strArguments +"\"");
        My_AddToLog("Output   ::");
        My_AddToLog("=======================================");
        listTemp = ListCreate( STRINGLIST );
        ListReadFromFile( listTemp, strLogFile );
        nSize = ListCount( listTemp );
        if nSize > 0 then
            for nIndex = 0 to nSize -1
                ListSetIndex(listTemp,  nIndex);
                ListCurrentString(listTemp, strTemp);
                My_AddToLog(strTemp);
            endfor;
        endif;
        My_AddToLog("=======================================");
        ListDestroy ( listTemp );
    end;

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •