Winapi 尝试在控制台应用程序中自动化流程
我试图让我的控制台应用程序模拟拖放文件,到目前为止,我还没有运气 系统抛出一个win32异常,说明它找不到该文件,因为我知道这并不是真正的问题,我希望有人能够解释可能导致这种行为的原因 我怀疑它可能是DEP。我可以拖放文件,进程会按预期运行,但我需要将其自动化 我已经创建了一个filewatcher,现在正在尝试找出如何让代码工作,然后再将其作为windows服务 但现在我真的被这个win32错误困住了Winapi 尝试在控制台应用程序中自动化流程,winapi,console-application,Winapi,Console Application,我试图让我的控制台应用程序模拟拖放文件,到目前为止,我还没有运气 系统抛出一个win32异常,说明它找不到该文件,因为我知道这并不是真正的问题,我希望有人能够解释可能导致这种行为的原因 我怀疑它可能是DEP。我可以拖放文件,进程会按预期运行,但我需要将其自动化 我已经创建了一个filewatcher,现在正在尝试找出如何让代码工作,然后再将其作为windows服务 但现在我真的被这个win32错误困住了 public class Watcher { public static
public class Watcher
{
public static void Main(string[] args)
{
Run();
}
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void Run()
{
string[] args = System.Environment.GetCommandLineArgs();
// If a directory is not specified, exit program.
if (args.Length != 2)
{
// Display the proper way to call the program.
Console.WriteLine("Usage: Watcher.exe (directory)");
return;
}
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = args[1];
/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch jpg files.
watcher.Filter = "*.jpg";
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
// Begin watching.
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
Process.Start(e.FullPath + "c:\\demo\\kr-pano\\mpr.bat");
}
访问该链接以查看完整的win32异常详细信息。
显然,问题的原因是filesystemwatcher是单线程的,当我尝试启动新进程时,它会阻止旧进程运行。我所需要做的就是去掉一个新的runpano函数并从我的代码中调用它,它现在就可以工作了 将异常文本完全添加到问题中。不要使用外部链接。我担心格式化神会攻击我。我设法弄明白了。