Locating “Add Network Printer” 's exe location - c#

I was keen on using the Process class [C#] to open "Add Printer" wizard, but I was wondering what is the location of the wizard's exe? And if so, is there a way to open straight into the "Add a network, wireless or Bluetooth printer" section of the wizard?
I would be glad if someone can help.
Thanks

You can do what you want by running a specific entry point in shell32.dll via rundll32.exe. The one you want is AddPrinter. For example;
ProcessStartInfo psi = new ProcessStartInfo {
FileName = "rundll32.exe",
CreateNoWindow = true,
Arguments = "shell32.dll,SHHelpShortcuts_RunDLL AddPrinter",
UseShellExecute = true
};
Process.Start(psi);

From a console run rundll32 printui.dll PrintUIEntry for a help dialog describing available command RunDll command lines.
To launch the Install UI you need to execute rundll32 printui.dll PrintUIEntry /il
(/ip for a Network Printer)

Related

Add more than one arguments when launch a process c#

Hy,
I need to launch a vnc viewer in a winform (ultravnc in my case) and I need to send two parameters to see the remote desktop and after several issues, I can't find any solutions.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "C:/Program Files/uvnc bvba/ultravnc/vncviewer.exe";
proc.StartInfo.Arguments = host;
proc.Start();
the first argument "host" is the ip of the pc and that just work.
After that, ultravnc ask me the password for the remote desktop connection.
And this is where I can't find any solutions :
1)I try to add a second arguments :
proc.StartInfo.Arguments = mdpVNC;
But VNC take this as a replacement of the "host" variable.
2)I try to use the SendKeys class but it doesn't work
3)I try the property "PasswordInClearText" but that doesn't work either.
I try several things and I don't want to use an external package (like vncSharp or other, because these solutions don't suit me)
I need help plz.
Thanks in advance.
StartInfo.Arguments is a string, and you put in there the arguments. Make the string that has the arguments as you would write them in the command line. For example:
startInfo.Arguments = "host -dsmplugin msrc4plugin.dsm";
That is for the first example in UltraVNC Viewer Commandline Parameters
.
Or whatever you need.

How to run chkdsk on drive without command prompt in c#

I searched on internet and found many possible ways of running chkdsk utility in c# using cmd.exe as file name and passing command as /c chkdsk drive_letter:/f /x
But I want to run chkdsk utility on drive ,without involvement of cmd.exe i.e; Purely using internal features of c#.
Your suggestions are greatly appreciated.
Chkdsk is a console application. So how do you wanna start a console application without the console? The only thing you can do is hiding the window from the user.
As you for sure already noticed: MSDN - Chkdsk
According the console-window:
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
This together should bring you to your goal.

Failing to run C# process as different user

I'm trying to run djoin.exe tool with System.Diagnostics.Process from a C# service using a different user (not as the service user).
The process returns code -1073741502.
In the event log I can see:
Application popup: djoin.exe - Application Error : The application was
unable to start correctly (0xc0000142). Click OK to close the
application.
No stderr or stdout.
Here is the process configurations I used:
ProcessStartInfo startInfo = new ProcessStartInfo
{
Arguments = "/Provision /Domain domain.com /Machine PC12 /SaveFile NUL /printblob",
WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
FileName = "djoin.exe"
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow =true,
Domain = "domain.com",
UserName = "other-user",
Password = "***"
};
if (username!=null)
{
startInfo.Domain = domain;
startInfo.UserName = username;
startInfo.Password = ToSecureString(password);
}
p = new Process { StartInfo = startInfo };
p.Start();
When using the RUNAS command, everything works fine.
What is the problem?
Seems like it is a permissions issue. This can either be at the folder level of where the exe is located, or to do with the user that the process is running under.
To diagnose this, you can first go to the folder where the exe is located. Then right click and set the permissions to "everyone" with full control. Then try to run again and see if you get the same message.
Also when you run Visual studio, at the start, right click and run as administrator. I take it from your comment that this works OK, leading me to believe it is in fact permission related. e.g. Are the different users in the same domain? Once you work out the permissions of the folder where the applcation lives, create an account with permission on that folder and then have whatever process schedules/runs the exe to execute under that account.
Update - the comments above prompted another idea, you could use system.diagnostics to write eventlog entries at each point of the code, to help determine what is going wrong. Another tool that may be of use if WinDBG to get more info about what is throwing that exception.

Run process under current user

There is "Setup project" in VS. During installation I launch another process:
System.Diagnostics.Process process = new System.Diagnostics.Process();
//fill StartInfo and run call Start()
process.Start();
If I run installer under Windows 7 and install for "Everyone", process start under the SYSTEM. If I install "Just for me", process start under Current user. How do I always start process under Current user?
I have found very simple solution. All that you need it just create a new class and copy text from this link.
To launch the process call ProcessAsUser.Launch("program name");
I had a similar problem: My setup extension (custom action) needed Admin privileges which brought up an elevation box. After I start my application at the end of "Just for Me" the process had settings that were made for the admin context. For example my user account likes to see all extensions of files in Windows Explorer but the admin account was configured to hide them. So in every file open box I couldn't see the extensions. To cure this this piece of code worked:
ProcessStartInfo startInfo = new ProcessStartInfo(ShortcutTarget);
startInfo.LoadUserProfile = true;
startInfo.UseShellExecute = false;
Process.Start(startInfo);
It works only in "Just for Me" mode, in "Everyone" the admin's settings are used. But this is ok for me.
Use ProcessStartInfo class and its property UserName, then use it as argument for Process.Start static method.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Process.Start(startInfo);

Open windows explorer with WPF application directory

I want to open application directory with button click. i get such error
Does anyone have an idea?
If you set UseShellExecute to true, then you can use Process to open a directory. For example, this will open the C:\ drive. You can specify any path you want.
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = #"C:\";
process.Start();
This is similar to using the Run dialog from the start menu. For instance, even though a Word document is not a program, using Shell Execute will allow you to "Start" a word document by using whatever program is associated with it. Likewise the same with a directory.
Have you tried "explorer.exe {0}" ? Explorer is the process you want, and the argument your intended path.
Try setting the ProcessStartInfo.Verb to "Open".

Categories

Resources