Jump to content

Recommended Posts

Posted

I am trying to use the RunAs function to kick off an MS SQL Management Studio process with a specified user.

I can get the process to run with "Run", but "RunAs" does not start the process.  Is there a way to debug it to see what is not working?

I can get RunAs to work fine with other processes (eg:  notepad.exe, cmd.exe, etc.)

Here is my code snippit:

This Works:

$ConnectionClientPID = Run("C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Smss.exe", "", @SW_SHOWMAXIMIZED)
$ConnectionClientPID = Run("C:\PROGRA~2\MICROS~1\110\Tools\Binn\MANAGE~1\Ssms.exe", "", @SW_SHOWMAXIMIZED)
$ConnectionClientPID = RunAs($TargetUsername, $TargetDomain, $TargetPassword, 0, "notepad.exe", "", @SW_SHOWMAXIMIZED)
$ConnectionClientPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)
$ConnectionClientPID = RunAs($TargetUsername, $TargetDomain, $TargetPassword, 0, "cmd.exe", "", @SW_SHOWMAXIMIZED)
$ConnectionClientPID = Run("cmd.exe", "", @SW_SHOWMAXIMIZED)

This does not work:

$ConnectionClientPID = RunAs($TargetUsername, $TargetDomain, $TargetPassword, 0, "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Smss.exe", "", @SW_SHOWMAXIMIZED)
$ConnectionClientPID = RunAs($TargetUsername, $TargetDomain, $TargetPassword, 0, "C:\PROGRA~2\MICROS~1\110\Tools\Binn\MANAGE~1\Smss.exe", "", @SW_SHOWMAXIMIZED)

Any thoughts?

Posted

@Andy_Jones,

welcome to AutoIt and to the forum.

RunAs() supports several modes of connection, specified by the 4th parameter ("logon_flag" in the help file). i see you keep it at 0, ($RUN_LOGON_NOPROFILE) while i would try to use 1 ($RUN_LOGON_PROFILE). this is because the program you attempt to run no doubt makes use of user-specific data stores, like the temporary files folder %TEMP% or the HKCU registry hive, which are not available at logon flag 0.

if you need the alternate user account only for network authentication, then flag 2 ($RUN_LOGON_NETWORK) would be adequate. then, your regular user account would operate the front-end program, while network authentication to the back-end SQL server will be using the alternate user account.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Posted

Thanks!  Setting the logon_flag to 1 ($RUN_LOGON_PROFILE) seems to have done the trick.  When I use 2 it does some funky things within the program, and I really want to execute all with the supplied un/pwd, rather than just the network authentication.

$ConnectionClientPID = RunAs($TargetUsername, $TargetDomain, $TargetPassword, 1, $ExecutionScript, "", @SW_SHOWMAXIMIZED)

This command seems to work for my POC ... now to get it into a Production state ....

Thanks again!  All I had to do was ask someone who knew better than me (I coulda saved 12 hours of banging my head if I had done it sooner :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...