Qt5 Windows boot up

Source: Internet
Author: User

Why is the program running directory with registry setting on boot all system32?

Wrote a program in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run to add the boot entry (normal work), but the egg hurt things happened, The working directory where the program starts automatically is not the directory where the executable is located, but System32 ... As a result, the call to the program in the same directory as the executable file will fail directly through the ". \\xxx.exe" method.

Seeking explanation and rescuing tat


A: Yes, the Registry's startup items, working directory estimates inherit the parent process's working directory, that is, the System32 directory.


The solution is also relatively simple:
1 If you write the program, your own work to adjust the directory on the line, as if setcurrent**directry or something, you check.

2 If the program is not written by you, there is a simple way to do a shortcut to the program, set up the directory in the shortcut, and then write the shortcut as a startup item in the registry.


Modify working Directory
    • You rarely need this operation if you use it, please note

BOOL Qdir::setcurrent (const QString & path) [Static]

    • Instead of

BOOL QDIR::CD (const QString & dirName) bool Qdir::cdup () void Qdir::setpath (const QString & Path)

Method 1: Set the currently running directory in the program code. However, this method can only be used for fixed installation directory software

Method 2: This simple method is to ensure that the desktop shortcut can not be modified, if modified, boot start also can not be

method to get the current desktop path:

QString desktop_path = qstandardpaths:: Writablelocation (qstandardpaths:: desktoplocation);

The method above will encounter

Issues with Administrator permissions

Boot start and double-click Desktop Shortcuts open directories are different

Method 3: How to use DOS commands

    1. Create a background-initiated bat or JS file in the installation directory

    2. Set registry startup key value to the path of the bat or JS file generated in the previous step

Contents of the Test.bat file:

@echo off

Color 0a

Set Base_dir=%~dp0

%base_dir:~0,2%

pushd%base_dir%

"D:\Rt\body-detect.exe"

Contents of the Hiderun.js file:

New ActiveXObject (' Wscript.Shell '). Run (' cmd/c d:/rt/test.bat ', 0);

Where D:/test.bat is your batch path


Method 4: Use the VBS method

Start.vbs content: (Workaround for path with spaces)

Set ws = CreateObject ("Wscript.Shell")

PATH=CHR () & " D:\Rt\Test . bat "&CHR"

Ws.run Path,vbhide

Method 5: Use Bat to invoke JS file

CScript "C:/Program files/rt600/hiderun.js"

Here are a few experts to organize


Several ways to hide a batch run window.
(1) Implemented by batch processing commands. Cons: You'll see a window flash away. Advantages: Simple, directly add can.


Copy the Code code as follows:


@echo off
If "%1" = = "h" goto begin
Start Mshta vbscript:createobject ("Wscript.Shell"). Run ("" ""%~nx0 "" H ", 0) (window.close) &&exit
: Begin
:: The following is a normal batch command, cannot contain pause set/p and other interactive commands
Pause


(2) Use VBS scripts to implement shadowing. Cons: Call trouble points. Advantages: Basic See no traces (not absolute, refers to the general user)

Hiderun.vbs


Copy the Code code as follows:


CreateObject ("Wscript.Shell"). Run "cmd/c D:/test.bat", 0


Where D:/test.bat is your batch path
......................................................................................................................... ............
Another idea is to convert the bat to VBS, then VBS to generate a temporary BAT file, and then WScript.Shell.Run hide to start the temporary bat.
Hiderun.bat


Copy the Code code as follows:


Echo CreateObject ("Wscript.Shell"). Run "cmd/c d:/test.bat",0> $tmp. vbs
Cscript.exe/e:vbscript $tmp. vbs
Del $tmp. vbs


This batch does not actually hide its batch itself, but most of the following hides the principle and foundation of calling batch processing.
Hiderun.js


Copy the Code code as follows:


New ActiveXObject (' Wscript.Shell '). Run (' cmd/c d:/test.bat ', 0);


What are the benefits of using JavaScript? JS string variable can be used single quotation marks, so as to facilitate the command line as a parameter call, and JS very good support for multi-line statements; The separation is written as a line. Note that: JS to distinguish case, method
Parentheses must be used, and the end must have a semicolon. So it becomes the following command:


Copy the Code code as follows:


Mshta "javascript:new activexobject (' Wscript.Shell '). Run (' cmd/c d:/test.bat ', 0); Window.close () "


Typically, the system administrator pushes some scripts to the client and runs them, or copies the batch files to the clients that are run by the user themselves. However, most scripts will pop up a black background DOS window when running, which will leave many users unaware
And even mistakenly close the running window. Fortunately, the DOS window of a batch file can be hidden, and here are a few ways to hide the batch run window.
1. Basic
Hiderun.vbs
CreateObject ("Wscript.Shell"). Run "cmd/c D:/test.bat", 0
Where D:/test.bat is your batch path
Another idea is to convert the bat to VBS, then VBS to generate a temporary BAT file, and then WScript.Shell.Run hide to start the temporary bat.
Hiderun.bat


Copy the Code code as follows:


Echo CreateObject ("Wscript.Shell"). Run "cmd/c d:/test.bat",0> $tmp. vbs
Cscript.exe/e:vbscript $tmp. vbs
Del $tmp. vbs


This batch does not actually make its batch itself hidden, but most of the following hides the principle and foundation of calling batch processing.
Hiderun.js
New ActiveXObject (' Wscript.Shell '). Run (' cmd/c d:/test.bat ', 0); What are the benefits of
using JavaScript? JS string variable can be used single quotation marks, so as to facilitate the command line as a parameter call, and JS very good support for multi-line statements; The separation is written as a line. Note that: JS to be case-sensitive, the method
must be in parentheses, the end must have a semicolon. So it becomes the following command:
Mshta "javascript:new activexobject (' Wscript.Shell '). Run (' cmd/c d:/test.bat ', 0); Window.close () "
2. Use a shortcut
If you want to hide a batch itself, you can refer to a shortcut in the attachment to modify the associated path in the attachment to hide the start of your batch. You can use VBS to create an. lnk, in fact, with a batch (echo a
vbs out)
3. Use System services
to set up a system service and then start the service to start the batch process. The disadvantage is that the startup service is slow and requires Administrator privileges
Runassrv add/cmdline: "c:/windows/system32/cmd.exe/c d:/test.bat"/name: "Mysrv"
net start Mysrv
4. Use at to schedule tasks
use at to establish a scheduled task that can be run in the background without entering the/interactive parameter. However, the use of at must have administrator rights
at 09:10 "cmd/c d:/test.bat"
and then at 9:10 the system will automatically run the bat

with system privileges in the background.

5. Using the Ftype file association
Ftype Batfile=c:/windows/system32/mshta "javascript:new activexobject (' Wscript.Shell '). Run (' cmd/c%1 ', 0); Window.close (); "
6. Other users
Windows 2K/XP supports multiple users, and if you can log on to another account's desktop in the background and run a batch, you can achieve the hidden goal completely.
7. Compiling into an executable file

Many methods can be implemented, the tool can be directly used to have Quick Batch file compiler.

This article is from the "QT Development" blog, make sure to keep this source http://2161404.blog.51cto.com/2151404/1825573

Qt5 Windows boot up

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.