|
I may be totally wrong at this but it looks like you're starting a background thread via
new Thread(ThreadStartDelegage) . That's fine so far.
But the background thread itself wraps its work in a Dispatcher.Begininvoke() so that it actually runs, and Sleep() s, in Dispatcher 's thread. This can or can not be the main thread, depending on how you created Dispatcher .
Ciao,
luker
|
|
|
|
|
I'm not sure which method to use (dispatcher or not). All I do know is that I need the process to run asynchronously from the main thread and to not block the UI while it checks for the presence of those files on the mobile computer. I have another glitch with it: the files may already be present on the device from a previous run, and so just checking for the presence of those files is a bad idea. What I really need to check for is if the EXE that I kick off on the mobile computer is finished, and that the text files that it writes to are available. There are some instances where I try to copy the file back to the desktop PC and the RAPI service can't copy it because the process running on the mobile computer still 'owns' it. Since there isn't a way for me to monitor that process directly, I've decided that sleeping for 5 seconds is enough. I want that sleep, however, to be asynchronous and not blocking the main UI. When a device connects and ActiveSync brings up its windows, I want to minimize them. If those windows are over top of my application and I minimize them, the sleep is currently blocking the UI and so the UI window shows remnants of those ActiveSync windows until the sleep finishes and the UI updates again.
Regards,
Scott
|
|
|
|
|
You have BobJanova's answer that does the file lookup in a separate thread without blocking the UI.
But regarding the other problems you mention, I suggest you should think again if it's worth developing the file handling way. You already mentioned that in the long run you would rather choose a socket-based communication. Maybe now is the time to get that version going.
Ciao,
luker
|
|
|
|
|
private void MonitorOEMInfoProcess()
{
System.Threading.Thread MonitorThread = new System.Threading.Thread(
new System.Threading.ThreadStart(
delegate()
{
while (!m_rapi.DeviceFileExists(@"\Application\OEMName.txt") || !m_rapi.DeviceFileExists(@"\Application\OEMVersion.txt"))
{
System.Threading.Thread.Sleep(1000);
}
}));
MonitorThread.Start();
}
Dispatcher is for synchronising things back to the main thread, you don't need it here.
|
|
|
|
|
The first code works, however I need to be able to read contents of multiple files from a particular directory.
Start simple and build from there I figure. Doing something wrong somewhere, as the 2nd code only brings up the dos window without any data.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace readtest
{
class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader("C:\\Users\\Random.txt");
string str = sr.ReadLine();
string[] words = str.Split('|');
foreach (string word in words)
{
Console.WriteLine(word);
} Console.ReadKey();
}
}
}
This is the one I need to have working. I must be structuring something wrong. I've tried different ways, but no luck.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string[] files = Directory.GetFiles("C:\\Users", ".txt");
foreach (string file in files)
{
StreamReader sr = new StreamReader(file);
string str = sr.ReadLine();
{
Console.WriteLine(file);
}
} Console.ReadKey();
}
}
}
|
|
|
|
|
Member 8363084 wrote: string[] files = Directory.GetFiles("C:\\Users", ".txt");
you have to use * here as
string[] files = Directory.GetFiles("C:\\Users\\", "*.txt");
regards
|
|
|
|
|
try
string[] files = Directory.GetFiles("C:\\Users\\", "*.txt");
Although it may read a bit better with an @ sign
string[] files = Directory.GetFiles(@"C:\Users\", "*.txt");
"You get that on the big jobs."
|
|
|
|
|
To cut to the chase, our current connection string is:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES;'
We really do not have the option of pushing a TypeGuessRows registry change to all users in order to force Excel to scan the whole column.
Can TypeGuessRows be given as an extended property to the ACE Provider?
Note: I know this isn't necessarily a C# specific question, but I'm writing in C# using an OleDbCommand, using the connectionString above.
"I need build Skynet. Plz send code"
|
|
|
|
|
There's no way to force TypeGuessRows in the connection string to a different value. I think your only option is to append "IMEX=1" to the connection string, which forces Excel to read all column data as text only. You'll then have to parse out out values from the strings returned.
|
|
|
|
|
btw, MS advised that the following should be correct:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES;Imex=1;ImportMixedTypes=Text;TypeGuessRows=0;
"I need build Skynet. Plz send code"
|
|
|
|
|
Update 1
CreateFile hooking now works, but only when I suspend the state of the program when it is started, hook the process and then resume the process. I need to be able to do this when a process is opened without interacting with my program. (Meaning I am not able to start it suspended, I need a way to hook the process start or something.) It has been suggested to use Drivers... I'm all ears!
Next issue, when I hook an already running process, I need to be able to determine the file handle linked to gw.dat, and reopen the file to that same handle using ReOpenFile and new share peramaters. Are there any ideas on how to do this? I am not familiar with doing something like this, much less in an unmanaged environment....
Related Questions:
WIN32 API override (Specifically CreateFile) in C# [Solved and very helpful]
How to tell what method opens a file [Solved and not helpful]
Suspend specific process on launch C# [Not Solved, hoping for easier answer...]
Run code inside process with EasyHook
Change a handle in unmanaged code without pre-existing knowledge of process internals [From injected DLL]
Original
Note: I figured I would post this here to get input, and in case anyone tries something similar in the future.
Before you read any further please understand that I do not intend to go any farther then allowing the client to be run more then once. The only advantage will be the same as having two computers next to each other.
I am using C# with EasyHook.
Background: Guild Wars is an MMORPG, for the most part there are mainly only two files. gw.exe which is less then a MB is executed, opens gw.dat (With exclusive rights), checks for updates, loads the rest of the game from gw.dat. gw.dat just holds everything else.
gw.exe makes sure it is not running already when it first starts, and if it is it will just force the prior process to the foreground. If you remove the mutex you cannot properly open a second gw.exe because the first has exclusive rights to the one and only gw.dat.
Yes, it is possible to remove the mutex and run multiple gw.exe processes pointing to different gw.dat files with some registry changes but the gw.dat gets over 4GB and it is just annoying.
Possible Solution: Trough looking around I have put together a DLL, and can successfully inject it into the gw.exe process using EasyHook. I can hook methods of other DLL's, and can interface with the injecting program. Originally it had been suggested I hook CreateFileW and change the call so it does not force exclusivity to the file. It turns out that either I hook the process too late for CreateFileW is not the function used to connect to the file. (Figured this out)
It was also suggested that I could call ReOpenFileW to change current handles to gw.dat to share mode. I can't seem to be able to run anything that isn't inside a hook so I can't call ReOpenFileW. (Though I can hook it)
Intended Result: Basically, what I intend to achieve is injecting a DLL into gw.exe, forcing it to remove a file lock, and remove the mutex (mutex can be done externally but I figure while I'm in there why not?)
Are there any ideas? Alternative solutions?
I have been working on this easyhook solution for a few days now, but in all honesty if it is doomed, or there is an easier way to do this I am all ears!
Quick Note: While doing something like this is against the EULA of the game, there has never been a problem with it in the past and there have been no bannings for this specific type of modification!
Also, if you want to try your hand at doing this or want a first hand look at what is being done by gw.exe (I tried to understand the assembly but I never learned that art....) The gw.exe can be downloaded here, and can be run without an account. You just can't play the game. If needed I can upload my current source! I'll have to clean it up a bit though....
modified 9-Nov-11 22:19pm.
|
|
|
|
|
How do you start/hook? Do you start the gw.exe process in a suspended state?
|
|
|
|
|
I hand't thought of doing that actually... I was intending to hook every process run automatically without needing to start the process with my code at all. Though I suppose suspended state would just make sense till I get things running....
At the moment I detect process start by watching for it with ManagementEventWatcher like so:
string queryString =
"SELECT TargetInstance" +
" FROM __InstanceCreationEvent " +
"WITHIN " + 1 + " " +
" WHERE TargetInstance ISA 'Win32_Process' " +
" AND TargetInstance.Name = '" + processName + "'";
string scope = @"\\.\root\CIMV2";
watcher.EventArrived += ProcessStarted;
watcher.Start();
I then hook using EasyHook:
Config.Register(
"A FileMon like demo application.",
"FileMon.exe",
"FileMonInject.dll");
RemoteHooking.IpcCreateServer<FileMonInterface>(ref ChannelName, WellKnownObjectMode.SingleCall);
RemoteHooking.Inject(
TargetPID,
"FileMonInject.dll",
"FileMonInject.dll",
ChannelName);
modified 8-Nov-11 15:01pm.
|
|
|
|
|
The hooking code might run too late then, or maybe it doesn't and there's an other problem, but I think it's a good theory
|
|
|
|
|
Is there a quicker way to hook a process or detect it's initialization? Such as hooking the process creator itself? Not sure what that would be on a global scale....
|
|
|
|
|
Is that even possible with user mode hooks? Well in any case I wouldn't go that far..
I know of no quicker ways, is starting the process from your program unacceptable?
|
|
|
|
|
Unfortunately for the end result it is.
The final product will basically sit there waiting for a user to run the game from anywhere using any method, hook it, remove the limitations for multi run, and wait for the next. That way there is no setup needed what so ever from the users, they don't need to mess around with shortcuts and command line arguments will run just fine. It will also allow things such as TexMod (Third party tool that modifies textures in memory, but requires the game to be run through it)
|
|
|
|
|
Ok that complicated matters. There's an article on cp that explain how to hook process creation[^] (not the same way you're hooking, but probably contains something useful), it's a bit heavy handed but could be worth a try
|
|
|
|
|
I saw that earlier.... I'm not too sturdy with C, but I suppose I can give it a shot tomorrow.
The only problem I can see with that is that I need to be able to inject into the process, and I can't see an obvious way to do so given that method....
|
|
|
|
|
I don't know either, but there's something I just thought about - what if you use that technique to hook CreateFile and OR in the sharing bits if the file being opened is gw.dat?
|
|
|
|
|
gw.dat is either not loaded using CreateFile, or it is being loaded so quickly that the current method can't even see it.
I can hook before WindowBlinds DLL's get in there, but not before the initial call to gw.dat... Which makes me think that CreateFile isn't being used, though I could be wrong.
|
|
|
|
|
Ok that's weird.. that other way to hook would definitely be on time if it's being opened with CreateFile, but if CreateFile isn't even used then I have no clue what's going on there
|
|
|
|
|
Ummm...Why try and piss on a spark plug when you could just run multiple virtual machines, each with its own copy of the game running?
|
|
|
|
|
Easy, the final product is going to be released (for free of course).
I can't release virtual machines, and they would take longer to set up then the current solutions. I am going for simplicity.
|
|
|
|
|
I wouldn't come here and ask for advice on hacking a MMORPG client, even if you have noble intent (which you didn't specify, so we can't assume either way.) Other people here probably play the game and don't want people interfering with whatever integrity the game still has.
That's kind of like going to an auto mechanics' forum and asking how to circumvent your car's ODB-II system so your car would pass inspection without repairing some problem, or going to a gun enthusiasts' forum and asking how you can manufacture parts that are illegal in your area.
No hate from me here. Just saying you probably shouldn't do this, nor should you ask here. Why run multiple instances, anyway? You can only control one instance of a game at a time.
|
|
|
|