Jump to content

[c#]WPF application: Permission problems


Go to solution Solved by GunnerMBT,

Recommended Posts

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

 

We are the tortured.
We're not your friends.
As long as we're not visible.
We are unfixable.

Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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.

We are the tortured.
We're not your friends.
As long as we're not visible.
We are unfixable.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

We are the tortured.
We're not your friends.
As long as we're not visible.
We are unfixable.

Link to comment
Share on other sites

  • Premium

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");
Link to comment
Share on other sites

  • Solution

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
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



  • Similar Content

  • Activity

    1. 4

      Feeding game source to LLM

    2. 0

      Quest 6/7 Problem

    3. 5

      Effect weapons

    4. 0

      [C++] Fix Core Downer Using Negative Number in GM Codes

    5. 3

      Crystal Metinstone

    6. 4

      Feeding game source to LLM

    7. 113

      Ulthar SF V2 (TMP4 Base)

    8. 4

      Feeding game source to LLM

  • Recently Browsing

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