|
Yeh i got ur mail.
Thank u very much.
|
|
|
|
|
questions should be answered within the thread, and not by e-mail.
That way anyone can benefit.
|
|
|
|
|
Yes there you are right but I send him more than 300 lines of code.
I think this is tooo long for this forum.
But here a short version (with out DLLImports, structs, ...):
public static void StartProcessOnActiveConsole(string szApplication, string szArguments, string szDirectory)
{
IntPtr hUserToken = IntPtr.Zero;
IntPtr hDuplicatedUserToken = IntPtr.Zero;
IntPtr lpEnvironment = IntPtr.Zero;
IntPtr hProcess = IntPtr.Zero;
IntPtr hThread = IntPtr.Zero;
try
{
uint dwSessionId = 0xFFFFFFFF;
dwSessionId = WTSGetActiveConsoleSessionId();
if (dwSessionId == 0xFFFFFFFF)
return;
if(!WTSQueryUserToken(dwSessionId, ref hUserToken))
throw new Exception("WTSQueryUserToken failed. GetLastError() = " + Marshal.GetLastWin32Error());
if(!DuplicateTokenEx(hUserToken, 0x02000000 , IntPtr.Zero, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, TOKEN_TYPE.TokenPrimary, ref hDuplicatedUserToken))
throw new Exception("DuplicateTokenEx failed. GetLastError() = " + Marshal.GetLastWin32Error());
if(!CreateEnvironmentBlock(ref lpEnvironment, hDuplicatedUserToken, false))
throw new Exception("CreateEnvironmentBlock failed. GetLastError() = " + Marshal.GetLastWin32Error());
STARTUPINFO startupInfo = new STARTUPINFO();
startupInfo.dwSize = (uint)Marshal.SizeOf(startupInfo);
startupInfo.pReserved = IntPtr.Zero;
startupInfo.szDesktop = "winsta0\\default";
startupInfo.pTitle = IntPtr.Zero;
startupInfo.dwX = 0;
startupInfo.dwY = 0;
startupInfo.dwXSize = 0;
startupInfo.dwYSize = 0;
startupInfo.dwXCountChars = 0;
startupInfo.dwYCountChars = 0;
startupInfo.dwFillAttribute = 0;
startupInfo.dwFlags = 128 ;
startupInfo.wShowWindow = 0;
startupInfo.wReserved2 = 0;
startupInfo.lpReserved2 = IntPtr.Zero;
startupInfo.hStdInput = IntPtr.Zero;
startupInfo.hStdOutput = IntPtr.Zero;
startupInfo.hStdError = IntPtr.Zero;
PROCESS_INFORMATION processInformation = new PROCESS_INFORMATION();
StringBuilder szCommandLineBuilder = new StringBuilder(32768);
szCommandLineBuilder.Append("\"" + szApplication + "\" " + (string)((szArguments == null) ? string.Empty : szArguments));
string szDir = ((szDirectory == null) || (szDirectory == string.Empty)) ? null : szDirectory;
if(!CreateProcessAsUser(hDuplicatedUserToken, null, szCommandLineBuilder, IntPtr.Zero, IntPtr.Zero, false, 0x00000400 , lpEnvironment, szDir, startupInfo, ref processInformation))
throw new Exception("CreateProcessAsUser failed. GetLastError() = " + Marshal.GetLastWin32Error());
hProcess = processInformation.hProcess;
hThread = processInformation.hThread;
}
finally
{
}
}
Greetings
Covean
|
|
|
|
|
Hi!!
1) I want to develop a program to hook on winspool.drv and be noticed whenever StartPagePrinter and EndPagePrinter functions are called. 've searched extensively having no luck. Wonder if you could help me by providing some sample codes or tutorials because I'm not familiarized with hooking apis.
2)The final goal of my program is to append some information on the printed pages sent by any application, is that possible?
Thank you!
|
|
|
|
|
I need to reference a combobox value (selectedvalue) on another form to the current form. How can I do this please?
I tried setting the combobox modifier to 'Public' and while in NewForm using MainForm.myComboBox.selectedValue without success.
|
|
|
|
|
Its bad practise to make such properties public as it lessens the object orientation of the control containing the combo box and starts going down the route of coupling the 2nd form to the 1st.
The thing to do is to raise an event in the first form (the one containing the combo box) that the second form subscibes to. The event should probably (depending upon your requirements) be raised when the combo box seleceted value changes.
Another way to solver you problem is to implement a model-view-viewmodel pattern, but this requires much more work if you have exisiting code.
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Many thanks for that. I shall proceed accordingly.
|
|
|
|
|
Hi guys..
I have developed a console application that migrates data present in xml file to my database.. my console application asks the app name from the user and based on the name entered by the user the application migrates only those records corresponding to that app name.. Now my question is after the migration is done my console application exits.. but i dont want it to exit, instead it must ask the user whether to exit if the user enters "exit" then it must exit otherwise the console application should repeat its migration process from the beginning and ask the user the app name and so on it goes... how do i implement this logic???
Thanx in advance..
Regards,
Tash
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:54am.
|
|
|
|
|
Thanx it worked fine...
Regards,
Tash
|
|
|
|
|
Hey there Thashif
I'd use a while loop for that
Here's an example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleTest
{
class Program
{
static void Main(string[] args)
{
bool QuitProgram = false;
while (!QuitProgram)
{
Console.WriteLine("Please type your name or \"quit\" to exit");
string Response = Console.ReadLine();
if (Response.ToLower() == "quit")
{
QuitProgram = true;
}
else
{
DoWork(Response);
}
}
}
public static void DoWork(string Response)
{
Console.WriteLine("Hello {0}", Response);
}
}
}
Hope this helps
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Thanx alot.. ur code helped me alot... Million thanx
Regards,
Tash
|
|
|
|
|
Your welcome
PS: Please don't forget to mark the post good answer
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
I have win32 handle to some active window.
I need to simulate click on some button that exist on the window.
How can i do it ?
I know only the button text.
|
|
|
|
|
Use Spy++ (installed with Visual Studio) to find the window handle for the button, and then use InteropServices to post a click message with the hwnd of the button.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
No can do -
I need to simulate it in run time
|
|
|
|
|
Yanshof wrote: simulate it in run time
That's what John's method allows you to do.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Spy++ gets you the hwnd.
You use the hwnd in your code.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I dont know how to use SPY++ in run time.
Is there some example ?
|
|
|
|
|
You could try running it... There's always google.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Use FindWindowEx[^] through pinvoke to find the button. You can use the handle for the parentwindow parameter and the caption of the button for the caption parameter. After getting the handle for the button you can send the BM_CLICK message using SendMessage[^].
|
|
|
|
|
Hi,
I have a large (0.5GB) XML file. I'm effectively copying it at the moment (with a view to changing certain values in the xml for testing). I'm using the XmlTextReader and Writer to perform this task.
Here is my code:
static void ProcessNode
{
if (reader.NodeType == XmlNodeType.Text)
{
string source = SecurityElement.Escape(reader.Value);
writer.WriteRaw(source);
return;
}
}
static void ProcessFile(XmlTextReader reader)
{
reader.Read();
using (XmlTextWriter writer = new XmlTextWriter(destinationPath, reader.Encoding))
{
Process(reader, writer);
while (reader.Read())
{
ProcessNode(reader, writer);
}
}
}
static void Main(string[] args)
{
using (XmlTextReader myReader = new XmlTextReader(sourcePath))
{
ProcessFile(myReader);
}
}
I'm having problems with escape sequences. The line string source = SecurityElement.Escape(reader.Value); Unescapes "'" to ' and "<" to < etc, which is desired. My problem is this: I have accented, non-english characters that have the escape sequences (e.g. Ú should be written as Ú). I cannot figure out how to Unescape such caracters.
As a side note, the line writer.WriteRaw(source); was writer.WriteString(source); both with and without the SecurityElement.Escape writes even the apostrophe unescaped, as well as the non-English caracters I'm still having problems with. This seems to be in direct opposition to http://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter.writestring.aspx[^] as far as I can tell.
If anyone can spot where I've gone wrong, it would be appreciated, this should have been a 1/2 day task for me and has taken a day so far....
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
I prefer to use an XmlDocument.
|
|
|
|
|
I agree, but reading the whole doc in results in out of memory exception. Reading nodes in at a time is much slower (factor of 100) than my current code, on a half-gig file. I'm hoping someone has a simple and fast answer to my problem....
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Don't use XML for half a gigabyte of data
|
|
|
|