Jump to content
  • 0
Vanilla

[c#]WPF application: Permission problems

Question

Hello everybody,

 

I've got a new problem here.

 

I'm trying to write a prepatcher which downloads the patcher music (very epic if you ask me :D) and - of course - the patcher itself if they aren't up to date. To clarify: It's a WPF application.

 

This is the code:

                ProcessStartInfo procinfo = new ProcessStartInfo();
                procinfo.FileName = @pathexec;
                procinfo.UseShellExecute = false;
                procinfo.Verb = "runas";
              
                try
                {
                    Process.Start(procinfo);
                }
                catch(Exception e)
                {
                    MessageBox.Show(String.Format("Es gab ein Fehler beim Starten des Patchers! /n" + e.ToString(), "Fehler", MessageBoxButton.OK, MessageBoxImage.Error));
                }

 

 

The variable pathexec consists of the absolute application path and the patcher downloaded (it's called metin2client.bin and yes this is the patcher).

The error is simple: It states that the program needs higher privileges to execute Process.Start(procinfo);

This is the error in german:

System.ComponentModel.Win32Exception (0x80004005): Der angeforderte Vorgang erfordert erhöhte Rechte

Google didn't help. It always tells me how unusual the error is and that I need to run the program as Administrator. Yes, it's running if I start the program as administrator, but it doesn't solve the problem itself. It's completely unusual and it should not be. And I can't expect from everyone who wants to use the prepatcher to run it with Admin privileges. No one with a little bit cautionousness will do that and that's the right choice.

 

The path exists and is accessable.

 

The funnies thing: If I use an older version of my patcher, the prepatcher will download and run it without any problems! It's just the new application that won't start (but the error is still in prepatcher since it's the Process.Start()-Error that's causing trouble). Running the patcher alone (old or new version doesn't matter) works fine without any flaws.

 

Even these two lines won't help:

procinfo.RedirectStandardError = false;
procinfo.RedirectStandardOutput = false;

Still the same error.

 

I hope someone out there can help me since nothing worked so far.

 

Greetings,

Vanilla

 

Share this post


Link to post

7 answers to this question

Recommended Posts

  • 0

1.) Visual studio as Administrator

Running Visual Studio as Administrator works. If I run my application there it works too. But building it and running the created executable without VS will cause the error to appear again.

You should skim-read through this. This is your current scenario:

Prepatcher explicitly needs admin privileges, since you're now running in a high integrity level (VS ran as admin) it works fine. It should however prompt you with the UAC message upon hitting the "Debug or Run button", doesn't it?

This is confirmed by my second question:

 

Prepatcher as Administrator

Works without any flaws. If I don't run it as Administrator, it'll throw out the error again.

To fix this, I'd guess you have to edit the manifest file of the target process.

Edit: Also, try what @Sanchez said.

  • Love 1

Share this post


Link to post
  • 0

Tiny (not so relevant, but still relevant :P) things:

-> You should use the standard naming conventions of C# (procinfo should be procInfo, for example). This is entirely up to you, these are just the usual guidelines.

->

MessageBox.Show(String.Format("Es gab ein Fehler beim Starten des Patchers! /n" + e.ToString(), "Fehler", MessageBoxButton.OK, MessageBoxImage.Error));
Are you sure you didn't mean:

 

MessageBox.Show(String.Format("Es gab ein Fehler beim Starten des Patchers! /n {0}", e.ToString()), "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
Why would pass all those arguments to String.Format if you have no place-holders? Also, for string concatenation you don't need to use String.Format.

-> Might I recommend using another approach on the "logging mechanism"? Regardless of the size of the project, a centralized logging class should be a better approach, one that would enable you to alert the user with custom messages just by changing the message in one place.

The main issue now, if I got it right, you don't want to obligate the user to execute as administrator, then why this:

 

procinfo.Verb = "runas";
This will prompt the user with the UAC message, asking for higher permissions...

Share this post


Link to post
  • 0

Yeah, just edited a code, the original patcher is from hanashi. I'm fixing it, didn't saw that.

 

To the error:

No, the procinfo.Verb = "runas"; doesn't cause the error. I only implemented it after I already had the error but it didn't solve it.

And there's no UAC message and still the error remains.

Share this post


Link to post
  • 0

If you run Visual Studio as administrator, and execute the prepatcher within it, does it work? If you run the prepatcher as admin (without VS), does it work? Lastly, if you run the patcher with double-click (normal execution), does it ask for higher level privileges? And you can remove the:

procinfo.Verb = "runas"
Given that you don't want higher level privileges.

Share this post


Link to post
  • 0

I already removed the line, still nothing changed.

 

1.) Visual studio as Administrator

Running Visual Studio as Administrator works. If I run my application there it works too. But building it and running the created executable without VS will cause the error to appear again.

 

2.) Prepatcher as Administrator

Works without any flaws. If I don't run it as Administrator, it'll throw out the error again.

 

3.) Patcher with double click

I need to rename it to metin2client.exe

If I do so it runs without Admin privileges. So yes, it's working.

Share this post


Link to post
  • 0

I don't really understand your problem, but why you use ProcessStartInfo for a simple exe starting? If your binary extension is .bin and not .exe then you can run it from command line.

            // If your binary extension is not .exe
            System.Diagnostics.ProcessStartInfo patcherStart = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c start metin2client.bin");
            patcherStart.WindowStyle = ProcessWindowStyle.Hidden;
            System.Diagnostics.Process.Start(patcherStart);

            // If your binary extension is .exe
            System.Diagnostics.Process.Start("metin2client.exe");

Share this post


Link to post
  • 0

Thank you very much. I saw the difference: The new patcher has a custom manifest.

 

I'm going to look for it and maybe I can fix the problem.

Share this post


Link to post

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...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.