Wallpaper Engine

Wallpaper Engine

View Stats:
KingEldarion Jun 17, 2017 @ 6:17am
Unity C# ProcessStartInfo.WorkingDirectory not working in Wallpaper Engine
Hi,

im working on a Desktop Modification with Unity. I have multiple Buttons which should start some Programs.
Everything works fine as long as i put it into Wallpaper Engine.
The problem is that it looks like it wouldnt really use the given Working Directory and uses the standard Wallpaper Engine one.
This is my Code:

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = fileSrc;
psi.WorkingDirectory = Path.GetDirectoryName(fileSrc);
Process.Start (psi);

As Wallpaper everything works only the psi.WorkingDirectory Line seems to not work. For some programms it is okay, because they dont use those Working Directory but some like my Music Player use those, which leeds into an empty Music Database for example.

Anyone has a Fix for this?

Greets KingEldarion
< >
Showing 1-11 of 11 comments
Biohazard  [developer] Jun 17, 2017 @ 2:04pm 
So psi.WorkingDirectory is definitely correct but in the launch process the current directory is just different for some reason?

I can't think of a reason why it would do this right now, I'm not modifying the working directory of child processes launched by a wallpaper process, but I do hook CreateProcess recursively to inject a DLL (well, just once, it was necessary for UE4 specifically). The working directory is just passed through though.
Last edited by Biohazard; Jun 17, 2017 @ 2:05pm
KingEldarion Jun 21, 2017 @ 4:29am 
I found something interesting, it seems to not be the Working Directory itself, but when I launch an Application with a File Dialog and i open this File Dialog it ever starts at C:/Windows/System32/config/systemprofile/
And in this folder there is an AppData Folder with stuff in it from the Applications i launched over the Desktop Mod. Those Data would never go there if i launch it normally via Explorer.

I still dont know what exactly is causing this but i think this could bring me closer to the solution.
Do you have any Idea Biohazard?

Edit:
Another interesting thing: In those File Dialogs if i try to go to the Desktop via Quicklinks on the left site it gives me following error at all Applications I launch in this way:

"C:\Windows\system32\config\systemprofile\Desktop" is not available.

Inn the Task Manager the executable which i put into the WP Engine and the Applications i launch from it have my Normal Main Username as their Username.

Edit 2:
As i made a little bit of research this is the Users Path for Services. Is it right that those WPE Applications run as a Service?
Last edited by KingEldarion; Jun 21, 2017 @ 7:40am
KingEldarion Jun 21, 2017 @ 8:02am 
OK i finally came up to the solution:

Because the executable is running as System User or Service, you have to change the User to the one you want to launch the applications with (Change password with your local usernames password and username with your Username):

System.Security.SecureString ss = new System.Security.SecureString();

foreach(char c in "password"){

ss.AppendChar(c);
}

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = fileSrc;
psi.WorkingDirectory = Path.GetDirectoryName(fileSrc);
psi.UseShellExecute = false;
psi.UserName = "username";
psi.Password = ss;
Process.Start (psi);

(Yeah i know it might not be the best solution to type in my password blank into the script but its only for my private use and i dont have the time and interest in making this more safe ;) )
Biohazard  [developer] Jun 21, 2017 @ 8:07am 
So the main process is not running as your normal Windows user? I.e. in task manager it doesn't show your own user for wallpaper32/64.exe?

It's not intended to be different from the normal user, but I guess it could happen if you use high-priority auto start. It uses a service but launches the program with CreateProcessAsUser using WTSQueryUserToken(WTSGetActiveConsoleSessionId()) as the current user. The service (wallpaperservice32_c.exe) will show a different user though.
KingEldarion Jun 21, 2017 @ 9:00am 
I enabled the high priority startup.

Following is shown me:
- walppaper32.exe -> Florian (my local username)
- walpaperservice.exe32_c.exe -> SYSTEM
- Desk.exe (My own Application) -> Florian

I looked this up earlier and thought that everything fits well when my Desk.exe is running wth my Username but that seemed to be an conflict with those User Directory i had in the Desk.exe, so i tried out to change the Username to my Local one and it worked.
Biohazard  [developer] Jun 21, 2017 @ 9:15am 
If you don't use high-priority, does the issue disappear then, aka you don't need to override the user in ProcessStartInfo?
KingEldarion Jun 21, 2017 @ 12:28pm 
After disabling High Priority it worked with the old Version where i didnt changed the User.

Will you provide a fix for this at some time, so i can have both, startup without User change and High Prio?

Anyways thx for dialog, really apreciating that there are still some devs out there who care about project and community, keep that work going ;)
Biohazard  [developer] Jun 21, 2017 @ 12:48pm 
If I can figure out what to change, it should just be a matter of changing the code that launches the process. I don't know of a better way than WTSQueryUserToken + CreateProcessAsUser though.

Also I wonder where it actually goes wrong, since it shows the correct user in task manager. Maybe it is just launched too early in the end?

Could you enable high-priority, close the program over the tray icon and then restart the service (Wallpaper Engine Service) in task manager? That should restart the program through the service. Does this still have the issue? If you could check this, it should show whether it's launching too early after logon or if CreateProcessAsUser just doesn't work as expected.
Last edited by Biohazard; Jun 21, 2017 @ 12:49pm
KingEldarion Jun 22, 2017 @ 7:31am 
I tried exactly what you said 3 times, evrything was still the same if i would launch it with High Priority
Biohazard  [developer] Jun 22, 2017 @ 7:39am 
Does the session ID in task manager maybe not match the other user processes?

The only thing I could think of is explicitly specifying a window station for the process with startupInfo.lpDesktop = L"WinSta0\\default"; so I added that.
KingEldarion Jun 22, 2017 @ 8:09am 
wallpaperservice has Session ID 0
wallpaper32 and Desk have Session ID 1
Firefox and Steam launched via Explorer also have Session ID 1 for example
< >
Showing 1-11 of 11 comments
Per page: 1530 50

Date Posted: Jun 17, 2017 @ 6:17am
Posts: 11