|
First of all many thanks for your help.
I changed my code like;
[DllImport("aygshell.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ExitWindowsEx([MarshalAs(UnmanagedType.U4)]uint dwFlags, [MarshalAs(UnmanagedType.U4)]uint dwReserved);
[DllImport("aygshell.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ExitWindowsEx([MarshalAs(UnmanagedType.U4)] ExitWindowsAction uFlags, [MarshalAs(UnmanagedType.U4)] uint dwReserved);
enum ExitWindowsAction : uint
{
EWX_LOGOFF = 0,
EWX_SHUTDOWN = 1,
EWX_REBOOT = 2,
EWX_FORCE = 4,
EWX_POWEROFF = 8
}
And I called the method
ExitWindowsEx(ExitWindowsAction.EWX_REBOOT, 0);
firstly I had an error "unable to load DLL" -0X8007007E-
and I found 'aygshell.dll' dll and copied it to C:\Windows\System32\aygshell.dll and also where my exe is.
And secondly I had an another error "An attempt was made to load a program with an incorret format" -0X8007000E-
What can I do, where is the wrong?
|
|
|
|
|
AYGSHELL is only available in Windows CE. Sorry, but I linked to the wrong version of the page. You're looking for this one[^].
|
|
|
|
|
final code is;
[Flags]
public enum ExitWindows : uint
{
// ONE of the following five:
LogOff = 0x00,
ShutDown = 0x01,
Reboot = 0x02,
PowerOff = 0x08,
RestartApps = 0x40,
// plus AT MOST ONE of the following two:
Force = 0x04,
ForceIfHung = 0x10,
}
[Flags]
enum ShutdownReason : uint
{
MajorApplication = 0x00040000,
MajorHardware = 0x00010000,
MajorLegacyApi = 0x00070000,
MajorOperatingSystem = 0x00020000,
MajorOther = 0x00000000,
MajorPower = 0x00060000,
MajorSoftware = 0x00030000,
MajorSystem = 0x00050000,
FlagUserDefined = 0x40000000,
FlagPlanned = 0x80000000
}
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
And I used the method;
ExitWindowsEx(ExitWindows.LogOff, ShutdownReason.MajorOther);(LogOff) It does work there is no problem but
ExitWindowsEx(ExitWindows.Reboot, ShutdownReason.MajorOther); Reboot It doesn't work.
I think there is something about 'AdjustTokenPrivileges' on page which you've sent me, but I couldn't integrated this part of code (I don't know where I have to write this code about 'AdjustTokenPrivileges' I've written something and I will be trying)
Although the remote pc is started Administrator user the method doesn't work with Reboot parameters.
Many Thanks for all.
|
|
|
|
|
I couldn't cope with the ex-code and I found different code which is similar to other.
Finall code is;
[StructLayout(LayoutKind.Sequential)]
private struct LUID
{
public long dwLowPart;
public long dwHighPart;
}
[StructLayout(LayoutKind.Sequential)]
private struct LUID_AND_ATTRIBUTES
{
public LUID udtLUID;
public long dwAttributes;
}
[StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFO
{
public long OSVSize;
public long dwVerMajor;
public long dwVerMinor;
public long dwBuildNumber;
public long PlatformID;
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
private struct TOKEN_PRIVILEGES
{
public long PrivilegeCount;
public LUID_AND_ATTRIBUTES laa;
}
[DllImport("advapi32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long AdjustTokenPrivileges(long TokenHandle, long DisableAllPrivileges, TOKEN_PRIVILEGES NewState, long BufferLength, long PreviousState, long ReturnLength);
private static bool EnableShutdownPrivledges()
{
bool EnableShutdownPrivledges = true;
long hTokenHandle = 0;
long hProcessHandle = GetCurrentProcess();
if ((hProcessHandle != 0L) && (OpenProcessToken(hProcessHandle, 40L, hTokenHandle) != 0L))
{
LUID lpv_la = new LUID();
string VBS0 = null;
string VBS1 = "SeShutdownPrivilege";
if (LookupPrivilegeValue(ref VBS0, ref VBS1, lpv_la) != 0L)
{
TOKEN_PRIVILEGES token;
token.PrivilegeCount = 1L;
token.laa.udtLUID = lpv_la;
token.laa.dwAttributes = 2L;
if (AdjustTokenPrivileges(hTokenHandle, 0L, token, 0L, 0L, 0L) != 0L)
{
EnableShutdownPrivledges = true;
}
}
}
return EnableShutdownPrivledges;
}
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long ExitWindowsEx(long dwOptions, long dwReserved);
[DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long GetCurrentProcess();
[DllImport("kernel32", EntryPoint = "GetVersionExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long GetVersionEx(OSVERSIONINFO lpVersionInformation);
private static bool IsWinNTPlus()
{
bool IsWinNTPlus = true;
return IsWinNTPlus;
}
[DllImport("advapi32", EntryPoint = "LookupPrivilegeValueA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long LookupPrivilegeValue([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpSystemName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpName, LUID lpLuid);
[DllImport("advapi32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern long OpenProcessToken(long ProcessHandle, long DesiredAccess, long TokenHandle);
When I use the method
long uflags = 2L; // reboot
if (EnableShutdownPrivledges() == true)
ExitWindowsEx(uflags, 0L);
else
ExitWindowsEx(uflags, 0L); // to run method in any case, but It doesn't work without
// giving privileges to a user.
The problem is to give privileges to a user When the 'LookupPrivilegeValue' runs 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt' error returns.
I think If I solve giving privileges to a user that will be ok.
Any suggestions you might have?
Thansk all Mr. Kreskowiak.
|
|
|
|
|
I found Sanur.exe as most of you might know that.
Start>Run>cmd
and Runas /u:domain\username "programName which you want to run" | "C:\where\Sanur.exe" password
it runs runas exe and Sanur.exe and I think sanur.exe reads the command line and sends the password and runs the program.
My question is how I can do that in .net (C# ). For example if I write;
string commandLine = "notepad.exe";
ProcessStartInfo ps = new ProcessStartInfo("cmd.exe", "/C \"" + commandLine + "\"");
ps.CreateNoWindow = true;
ps.UseShellExecute = false;
Process.Start(ps);
something like that it runs the notepad there is no problem.
So how I run an exe where is C:\xxx\123.exe using the code above.
if I set "u:domain\username "programName which you want to run" | "C:\where\Sanur.exe" password" parameter to commanLine variable it doesn't work.
How can I do that, Many thanks already.
|
|
|
|
|
I tried it out and it does work.
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe");
psi.Arguments = "/C \"C:\\Windows\\System32\\Runas.exe /u:domain\\username C:\\XXX\\123.exe | C:\\Sanur.exe password\"";
p.StartInfo = psi;
p.Start();
|
|
|
|
|
Hello All,
When i tried to add reference of EXCEL 11.0 library, it appeared in list with exclamation mark and I was having its namespace but i m getting errors while using classes of namespace excel and even i have errors and warnings as listed, please help!!!:
Error 1 The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)E:\RM\RunMac\RunMacro\Form1.cs
Warning 1 Cannot find wrapper assembly for type library "Excel".
sejal
|
|
|
|
|
Do you have the Microsoft office interop assemblies installed and referenced?
|
|
|
|
|
I havent checked it yet.. but i have MS EXCEL library 5.0 that has no problem while referencing.
sejal
|
|
|
|
|
Hi,
I need to run a exe file from the local system using a web page.My attempt show error.
My code to call the exe from a web page is :-
System.Diagnostics.Process.Start
(@"D:\ProgramFile\WindowsApplication1.exe", "" + UsrId + " " + TextBox2.Text + " ");
and
System.Diagnostics.Process.Start("notepad");
It is properly working in the local system using http://localhost. When i publish the application ie. run from a site eg: http://192.169.1.26/application/login.aspx from server system, the windows form is not display.
Error message:--
"An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll"
"Additional information: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."
"Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."
This is the error message in case of opening an windows form. No message is shown when i open a notepad, its not visible.
Regards,
YPKI
|
|
|
|
|
ypki wrote: When i publish the application ie. run from a site eg: http://192.169.1.26/application/login.aspx from server system, the windows form is not display.
Did you expect the windows form to appear in the machine where you are browsing the web page? If yes, you need to do some reading on how web applications works.
BTW, why do you want to launch some executable from a web application?
|
|
|
|
|
Yes, i need to appear the windows form in the machine and need to do some online works, using socket. The concept of yahoo messenger, but i need to open the .exe from a button click event from the website.
|
|
|
|
|
ypki wrote: The concept of yahoo messenger
Yahoo messenger is not opened from a webpage. It is a stand-alone application which communicates with a remote server.
ypki wrote: Yes, i need to appear the windows form in the machine
Then you need the executable file on this machine. It can't be launched through a web page which resides on a remote server. As I said, you need to do some reading on how web applications works.
|
|
|
|
|
I search lot in web for solving this..but no result
|
|
|
|
|
Your not getting the result you expect. All ASP.NET code runs entirely on the server and generates HTML pages which are sent to the client. So, on your server, you're trying to execute Notepad or something else, which will only result in the app being launched ON THE SERVER. You cannot launch an executable on the browser side from ASP.NET code. It can only be done, IF AND ONLY IF, the clients browser security settings are relaxed and only from client-side Java, JavaScript, or VBScript code.
|
|
|
|
|
i have username and password in sqlserver, i want to call the username and password in asp.net, please anyone help me, to give me the code in c#.
|
|
|
|
|
Are you in right forum.Please post you rquestion in ASP.NET forum.
Cheers!!
Brij
|
|
|
|
|
hi guys...
i dn know how to use connection zone in webparts. i need a sample code for this one.please help...
modified on Monday, December 29, 2008 2:08 AM
|
|
|
|
|
Hello everyone,
For a beginner of T-SQL for Windows SQL Server 2005 on Windows Server 2003, what is your suggested book?
thanks in advance,
George
|
|
|
|
|
I'd suggest this[^] and this[^]
BTW, you are in wrong forum
|
|
|
|
|
Hi Navaneeth,
I think the T-SQL Querying is not for beginners?
BTW: there is no SQL Forum here.
regards,
George
|
|
|
|
|
George_George wrote: BTW: there is no SQL Forum here.
There is!![^]
|
|
|
|
|
Thanks Luis,
I only see the 1st word which is general before.
regards,
George
|
|
|
|
|
Hi! Simple C# question, I'm just wondering the the connection will close in the code below:
try {
connection.Open();
command.ExecuteNonQuery();
throw new Exception();
} catch(Exception) {
throw;
}
finally {
connection.Close();
}
Rafferty
|
|
|
|
|
yes becouse finally block gets excecuted in any situation whether there is exception or code excecutes successfully.
rahul
|
|
|
|
|