473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Run cmd prompt as administrator in C#

85 64KB
Hi
i am trying to change the ip address of computer in windows 7 using netsh command in C# with the following code
Expand|Select|Wrap|Line Numbers
  1. string command = "netsh int ip set address= \"local area connection\" static " + ip_address + " 255.255.255.0 192.168.0.1";
  2.             ProcessStartInfo procStartInfo = new ProcessStartInfo()
  3.             {
  4.                 RedirectStandardError = true,
  5.                 RedirectStandardOutput = true,
  6.                 UseShellExecute = false,
  7.                 CreateNoWindow = true,
  8.                 FileName = "runas.exe",
  9.                 Arguments = "/user:Administrator \"cmd /K " + command + "\""
  10.             };
  11.  
  12.             using (Process proc = new Process())
  13.             {
  14.                 proc.StartInfo = procStartInfo;
  15.                 proc.Start();
  16.  
  17.                 string output = proc.StandardOutput.ReadToEnd();
  18.  
  19.                 if (string.IsNullOrEmpty(output))
  20.                     output = proc.StandardError.ReadToEnd();
  21.  
  22.  
  23.             }
  24.  
it is not giving any error or exception. but it is not changing the ip. whereas when i run the command prompt as administrator from start menu and type the command there, it changes the ip.
how can i run this prompt as administrator from C# code..?
any help will be greatly appreciate..

Regards:
Dec 31 '14 #1
0 4670

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: ML | last post by:
Is there anyway to get around the security prompt from Outlook when using the object in a vb.net winforms app? I want to be able to load the contacts lists from Outlook but each time it access it...
2
by: Simple Java Drinker | last post by:
I decided to reinstall the Windows XP on my computer by using the Repair Option. After typing "R" as required I am requested to input an administrator password. The problem is that no administrator...
1
by: grabro | last post by:
Having just upgraded to from Suse 10.0 to 10.1 mysql-administrator will not work. When I try to acccess it I get the following message. linux:/home/grabro # mysql-administrator...
2
by: Fred Heida | last post by:
Hi, Question on Vista Run As Administrator. If i have exe which creates a child process, using the Process class, and this exe is Run As Asministror, is there a way to have the child process...
22
epots9
by: epots9 | last post by:
I forgot how to fix this, so i was wondering: how can i get my computer (WIN XP Media Center SP2) to auto select my user account at the logon screen? I only have one account setup with a password....
1
by: Jack Russell | last post by:
Under XP I used the following code AppDomain.CurrentDomain.SetPrincipalPolicy(Security.Principal.PrincipalPolicy.WindowsPrincipal) Dim MyPrincipal As System.Security.Principal.WindowsPrincipal...
5
by: nagar | last post by:
I'm using the Process.Start method to launch an application from C#. How can I launch the App as Administrator in Windows Vista? Thanks. Andrea
0
by: David C | last post by:
I have an asp.net 2.0 internal web application that uses authentication mode="Windows" and identity impersonate="true" with a userName and password. Our photos (mostly jpg files) are stored on a...
1
by: Oolis Kraprin | last post by:
Hi, I have a program running with normal user privileges, that needs to update an entry in an ini file that happens to be in ProgramData, so that a server program, running as administrator can read...
10
dlite922
by: dlite922 | last post by:
Hey guys, I have a PC that is loaded with a program that restores the Windows XP image (Linux based, don't know the name) which restores the the OS from an image with each reboot, similar to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.