• wince Automatically Start Application with Command Line Parameters


    The short answer is that you cannot pass command line parameters to the application when using HKEY_LOCAL_MACHINE\Init to launch your application (although a command line parameter is passed to it for use with SignalStarted()). But maybe you really need to use this key to start your application because you don’t want a user to remove your application from the Startup folder, so let’s look at how this could be done.
    Since we can’t pass parameters to the application directly using the Init key, what we need to do is write a second application to do it. In this case, let’s assume that the application that you want to start is third-party application that does not call SignalStarted() so we will do that for it. What we will do is start the application using CreateProcess() and then call SignalStarted().
    #include <Windows.h>
    int WINAPI WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow)
    {
    PROCESS_INFORMATION pi;
    if (CreateProcess( TEXT("iesample.exe"), TEXT("\\Storage Card\\Index.html"), NULL, NULL, FALSE, 0,NULL, NULL, NULL, &pi))
    {
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    }
    SignalStarted( _wtol(lpCmdLine) );
    }
    This example will start iesample.exe with \Storage Card\Index.html loaded and displayed.
    The downside of this is that you probably need to be a software developer to turn this into an exe that you can use, if you are not then you probably won’t be using the Init key but instead will use the Startup folder.
     
    Startup Folder with Command Line
    You can’t put your application in the Startup folder and pass it command line parameters, but you can put a shortcut file to your application in the Startup folder and include the command line arguments in the shortcut file.
    A shortcut file is a file with a LNK extension that contains:
    <Number>#<Command> <Parameters>
    Where:
    Number is the number of characters after the pound sign (#)
    Command is the application that you want to run
    Parameters are the command line parameters to pass to the application
    So to start iesample.exe and load \Storage Card\Index.html, I created a file named StartExplorer.exe.lnk. I include the exe for two reasons; it makes it look like an exe to the user and the LNK extension will not be displayed. If you leave out the exe, it will still work but it will be displayed in the file explorer as StartExplorer.lnk which I think looks odd.
    The contents of the file are:
    37#iesample.exe \Storage Card\Index.html
    Now put this shortcut in the \Windows\Startup folder. The catch is that your Startup folder may not persist, but if you are developing the OS you can put this shortcut in the OS and use your DAT file to copy it to the Startup folder (see Platform Builder: Using Dat Files to Initialize the File System for more)
    Another solution would be to use a batch file, but I don’t think that has any advantage over a shortcut and it has a few disadvantages. The disadvantages are that your OS must include a command window and the command window will open before your application. But here is a simple batch file that opens iesample.exe and loads \Storage Card\Index.html:
    @echo off
    iesample \Storage Card\Index.html
     
  • 相关阅读:
    实用的设计模式【一】---类设计法则
    vimium 使用心得
    记一次给部门做分享的心得
    centos7安装docker和docker compose【转】
    docker 部署 jenkins
    centos删除docker0虚拟网卡
    CentOS7查看和关闭防火墙
    .Net Core Autofac实现依赖注入
    【转】Docker基础
    【转】使用Docker+Jenkins自动构建部署
  • 原文地址:https://www.cnblogs.com/zym0805/p/2213734.html
Copyright © 2020-2023  润新知