PowerShell Studio problems with alternate credentials

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
mkedaj
Posts: 6
Joined: Sun Mar 03, 2013 12:42 pm

PowerShell Studio problems with alternate credentials

Post by mkedaj » Tue Jun 10, 2014 2:59 pm

My environment:
Windows 7 x64
PowerShell Studio 4.1.61

I tried to use the runas and impersonate features of the packager and recognized that the do not work in my sample.

I then made a simple test case with the credential object:

$username = "Test"
$secstr = ConvertTo-SecureString -String 'Pa$$w0rd' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($username, $secstr)

start-process -FilePath "C:\Windows\System32\notepad.exe" -Credential $cred

User "Test" with password "Pa$$w0rd" was created before.
The result: ERROR: start-process : Dieser Befehl kann aufgrund des folgenden Fehlers nicht ausgeführt werden: Der Verzeichnisname ist ungültig.
Translation: The command could not be executed for the following reason: The directoryname is invalid.

The same code works in Powershell ISE, Notepad starts up in the Test account.

Please check and give advice.

Thanks
Martin

User avatar
mkedaj
Posts: 6
Joined: Sun Mar 03, 2013 12:42 pm

Re: PowerShell Studio problems with alternate credentials

Post by mkedaj » Thu Jun 12, 2014 2:38 am

Additiononal Info:

A local account is used.
This happens with my privat installation with Windows 7 Pro x64 and also with my installation at work (4.1.57) on Windows 7 Enterprise x64.


I can't use alternate credentials to start a process in any way:
  • no packaging with impersonation
    no packaging with RunAs
    no Start-Process -Credential ...
Don't tell me you cannot reproduce the issue. I found other posts with "The directory name is invalid" so it seems to be a common problem.

Are there any known workarounds?

Martin

User avatar
Alexander Riedel
Posts: 7051
Joined: Tue May 29, 2007 4:43 pm

Re: PowerShell Studio problems with alternate credentials

Post by Alexander Riedel » Thu Jun 12, 2014 3:59 am

Are you doing this in 32 bit mode? Try to package it as 64 bit executable.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
mkedaj
Posts: 6
Joined: Sun Mar 03, 2013 12:42 pm

Re: PowerShell Studio problems with alternate credentials

Post by mkedaj » Thu Jun 12, 2014 12:05 pm

Hi Alexander,

it doesn't matter what mode - it's all the same.
But a fortunate coincidence brouhgt me forward. Let me explain:

Today I worked at my company on my project and I thougt that it could be a good idea to convert my psf file into a project. I created a new form project and placed the project folder somewhere outside of my profile and spreaded my code over the files.
Then I tried to execute and ... I could not believe it - it worked!

Now at home I tried to figure out what's the special circumstance.

My file path until now:
D:\Users\Mr. X\Documents\SAPIEN\PowerShell Studio 2014\Files

May the folder with dot and space confuse Powershell Studio?

I created a similar folder structure:
D:\Test\Test. 1\Documents\SAPIEN\PowerShell Studio 2014\Test2

I placed my script there and ... it worked.

Now I started to move my test.ps1 step by step one folder upward in my profile tree.

At last "D:\Users\Mr. X\Documents\test.ps1" did not work but "D:\Users\Mr. X\test.ps1" did.

So I conclude it's a permission problem.

All my problems are solved by using a different path: RunAs and impersonate works in packaging; start-process with credentials in plain scripts too.

Hope this helps some others.

Martin

User avatar
mkedaj
Posts: 6
Joined: Sun Mar 03, 2013 12:42 pm

Re: PowerShell Studio problems with alternate credentials

Post by mkedaj » Tue Jun 24, 2014 4:26 am

Hi,
another finding related to this issue:

I created a package and when I tried to execute it I received an "access denied" error.
I copied the file into the same directory and the copy worked.
I compared the security permissions of the files and recognized that the package created by PowerShell Studio has replaced all inherited permissions with explicit permission ("Full Control" for System, Administrators and me).

My expectation was that the created exe inherits the permissions of the folder.

Martin

User avatar
Alexander Riedel
Posts: 7051
Joined: Tue May 29, 2007 4:43 pm

Re: PowerShell Studio problems with alternate credentials

Post by Alexander Riedel » Tue Jun 24, 2014 8:41 am

The exe is created via the Windows API CopyFile. It does whatever is defined by the permission structure on your system.
Since it copies the base engine from a template in your installation folder it most likely will copy the permissions from there along with it.

We generally recommend building locally and then deploying to your final destination to avoid permissions problems.

We are not setting or removing any particular permissions when creating an executable.
Alexander Riedel
SAPIEN Technologies, Inc.