The problem that I have is that when I try to open Skype using Process.start in C#, the Skype window opens but when I put the user and password, I can't log on. But when i go directly to "C:\Program Files (x86)\Skype\Phone\Skype.exe" and I choose "Run as different user" (Shift + right clic),the Skype window opens, I put the credentials and in that case it works.
In Windows I have logged in, as local user and the user I need to run Skype is a Domain user. The connection to skype is through proxy.
I have checked in task manager, and the process starts with the correct user but somehow the behavior is different when I do it right clicking the folder and from the Process.start.
Here is my code:
ProcessStartInfo oPi = new ProcessStartInfo();
oPi.Domain = "Domain";
oPi.UserName = "User";
oPi.Password = oSecureString;
oPi.FileName = "C:\\Program Files (x86)\\Skype\\Phone\\Skype.exe";
oPi.UseShellExecute = false;
Process oP = Process.Start(oPi);
Just put the code in the button's click event handler and use using System.Diagnostics as namespace to get Process:
protected void btn_Click(object sender, EventArgs e)
{
try
{
Process.Start("C:\\Program Files (x86)\\Skype\\Phone\\Skype.exe");
}
catch (Exception ex)
{
Response.Write("" + ex);
}
}
Related
I have two applications First one detects the USB/Portable HDD plugging in to the system, and this application then passes the detected Drive letter to another External application and External application ejects it.
The external application is always run as an administrator. It is working properly.
But there is an issue when "Do you want to run this application as admin YES/NO" popup appears, If I select Yes it works properly. Now If I select No even then the USB drive appears to be in use by First application and cannot be ejected manually.
My Code is given below
ProcessStartInfo start;
Process exeProcess = null;
try
{
start = new ProcessStartInfo();
start.Arguments = #"H:\";
start.Verb = "runas";
start.FileName = "Eject.exe";
start.WindowStyle = ProcessWindowStyle.Normal;
start.CreateNoWindow = false;
using (exeProcess = Process.Start(start))
{
exeProcess.WaitForExit();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
The Console output in the catch block shows the message "The operation has been canceled by user" but still the resource is in use.
Kindly guide me how to tackle this issue.
I have created a windows form program that does some Business Intelligence but have subsequently needed to access this via a webform. I am fairly new to programming so I don't know what can be achieved here. But essentially I am wanting someone to go on to the net and when the user presses a button it sends a message to the windows form executable in a file and tells it to run and then press a button on the form, which runs a method to generate images of graphs. Is this possible?
Here is the relevant code.
In the webform I have this button.
protected void rolloutSmartSheets(object sender, EventArgs e)
{
string message = string.Format("Starting processes");
ltMessage.Text = message;
Process process = new Process();
process.StartInfo.FileName = #"P:\Visual Studio 2013\Projects\Smartsheet\SmartsheetAPI\obj\Debug\SmartSheetAPI.exe";
process.Start();
message = string.Format("Ended all processes");
ltMessage.Text = message;
}
That runs the executable but it opens the windows form and I imagine if the executable is sitting on another computer wouldn't that open on that computer? In which case i want it to tell it to press this button on the windows form which runs the method I need and then the user doesn't need to worry about it.
public void commitToDatabase_Click(object sender, EventArgs e)
{
commitToDataBase();
}
If you are able to have the clients install something in advance, you can provide this functionality using a custom protocol handler.
Example protocol handler from MSDN Article
HKEY_CLASSES_ROOT
alert
(Default) = "URL:Alert Protocol"
URL Protocol = ""
DefaultIcon
(Default) = "alert.exe,1"
shell
open
command
(Default) = "C:\Program Files\Alert\alert.exe" "%1"
Then add a link onto your webform like this
href="alert://test"
As long as the client has the handler installed, both in the registry and the executable file, it will run C:\Program Files\Alert\alert.exe, passing "test" to it as the first paramater.
You can easily change this to provide the ability to run the local graph generator, and pass any parameters from the webform you might need.
I have tried to find this everywhere on the internet with no luck. I want to make my program launch after every login (LoginUI.exe). Is it possible to detect when the user has locked his/her computer (Winkey + L) and then launch my program? If this is not possible, then is there a way to detect once a user has just logged in?
You could write a program that monitors the user session state via SystemEvents in Microsoft.Win32:
// Put this somewhere in your console app/windows form initialization code.
SystemEvents.SessionSwitch += OnSessionSwitch;
// Put this method in your console app/windows form somewhere.
static void OnSessionSwitch(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLogon:
// User has logged on to the computer.
break;
case SessionSwitchReason.SessionLogoff:
// User has logged off from the computer.
break;
case SessionSwitchReason.SessionUnlock:
// The computer has been unlocked.
break;
case SessionSwitchReason.SessionLock:
// The computer has been locked.
break;
}
}
In your case, you could do Process.Start(...) when you detect either SessionLogon or SessionUnlock.
Looks like SO already has some information on this type of thing. A registry modification in c# looks like it will do the trick.
Programmatically start application on login
I think this is what you are looking for man! Here is the relevant snippet:
WshShell shell = new WshShell();
string shortcutAddress = startupFolder + #"\MyStartupShortcut.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "A startup shortcut. If you delete this shortcut from your computer, LaunchOnStartup.exe will not launch on Windows Startup"; // set the description of the shortcut
shortcut.WorkingDirectory = Application.StartupPath; /* working directory */
shortcut.TargetPath = Application.ExecutablePath; /* path of the executable */
shortcut.Save(); // save the shortcut
Hoping this question will get answered. Basically I am attempting to open an executable file from within an application I have created which runs on windows ce5 on a unitech barcode scanner using the .net compact framework 3.5. I have included a snippet of code where I attempt this.
Each time I debug the app via VS2008 I am getting a Win32Exception but with no further details (with or without the try catch statement). It does not tell me what the exception is nor does it provide an error code.
Here is the code I am using to try to start the process. Can you see anything wrong with it that may be causing an error? I have double and triple checked the filename and also the directory where it is stored so it is not that.
private void CustomButtonEvent(object sender, EventArgs e)
{
string buttonName = ((Control)sender).Name;
ProcessStartInfo processStartInfo = new ProcessStartInfo();
buttonName = buttonName.Remove(0, 3);
buttonName = buttonName.Replace(' ', '_');
switch (buttonName)
{//todo need to open the different exe's here
case "End_Of_Line":
{
MessageBox.Show(#"No app behind this button yet.");
break;
}
case "Asset_Tracking":
{
processStartInfo.FileName = "AssetTrackingScanner.exe";
processStartInfo.WorkingDirectory = #"\Flash Storage\CompoundingManagementScannerSuite\Applications\AssetTrackingScanner\AssetTrackingScanner\bin\Debug";
try
{
Process.Start(processStartInfo);
}
catch (Exception f)
{
MessageBox.Show(f.ToString());
}
break;
}
case "Stock Take":
{
MessageBox.Show(#"No app behind this button yet.");
break;
}
case "Despatch":
{
MessageBox.Show(#"No app behind this button yet.");
break;
}
}
}
I see two problems. First, CE requires fully qualified paths, so the processStartInfo.FileName should be something like this
processStartInfo.FileName =
#"\Flash Storage\CompoundingManagementScannerSuite\Applications\AssetTrackingScanner\AssetTrackingScanner\AssetTrackingScanner.exe";
Second, CE has no concept of a WorkingDirectory, so remove the call to set it.
I'm also a little concerned about the \bin\debug\ part of your path. Studio doesn't deploy to a bin\debug\ folder on the device. It build to one on the PC, but on the target device the only way it would be there is if you manually set it. This leads me to think you need to check your on-device applicatin path.
I'm learning about opening and saving files with C# and it seems that vista won't let my program save to a file on the root of C:\ , unless I run it in administrator mode.
Any ideas how to allow my program to play around with whatever files it wants?
Thanks!
private string name;
private void open_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
name = openFileDialog1.FileName;
textBox1.Clear();
textBox1.Text = File.ReadAllText(name);
textBox2.Text = name;
}
}
private void save_Click(object sender, EventArgs e)
{
File.WriteAllText(name, textBox1.Text);
}
To make your program start with administrator rights, you have to change the manifest. This can be done by Add New Item -> General -> Application Manifest File. Open the manifest and set "requestedExecutionLevel" to "requireAdministrator". When this is done, open the project settings and on the 'Application' tab choose your new manifest.
The program will run with your credentials, by default.
So, these do not have the right permissions to write to the root folder.
If you want it to run with other credentials you can us the runas command line to execute the application with other credentials.
Alternatively, grant more permissions to the account the application runs as.
There are several reasons for the UnauthorizedAccess Exception. Check one of those:
path specified a file that is read-only.
This operation is not supported on the current platform.
path specified a directory.
I accidently hit the third problem today ;-)