-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParams.cpp
More file actions
53 lines (41 loc) · 1.54 KB
/
Copy pathParams.cpp
File metadata and controls
53 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "stdafx.h"
#include "params.h"
#include "regvalue.h"
void Params::Save( LPCTSTR lpCmdLine)
{
if (( lpCmdLine == NULL ) || (lpCmdLine[0] == 0))
throw std::invalid_argument("Command line is required");
LPTSTR lpArgs = PathGetArgs( lpCmdLine );
CAtlString sApp(lpCmdLine);
PathRemoveArgs( sApp.GetBuffer() );
sApp.ReleaseBuffer();
CAtlString sDir;
DWORD dwLen = 0;
dwLen = GetCurrentDirectory( dwLen, NULL );
sDir.GetBuffer( dwLen );
dwLen = GetCurrentDirectory( dwLen, sDir.GetBuffer( dwLen ));
sDir.ReleaseBuffer( dwLen );
RegValue reg(HKEY_CURRENT_USER, c_szRegPath, true);
reg.SetString( c_szExecApp, sApp, ( sApp.GetLength() + 1 ) * sizeof( sApp[0] ));
reg.SetString( c_szExecArgs, lpArgs, ( _tcslen(lpArgs) + 1 ) * sizeof( lpArgs[0] ));
reg.SetString( c_szExecDir, sDir.GetString(), ( sDir.GetLength() + 1 ) * sizeof( sDir[0] ));
AttachConsole(ATTACH_PARENT_PROCESS);
DWORD dwProcessId = ::GetCurrentProcessId();
reg.SetDword( c_szExecId, dwProcessId);
}
void Params::Load( CAtlString &sDir, CAtlString &sApp, CAtlString &sArgs, DWORD &dwProcessId)
{
RegValue reg(HKEY_CURRENT_USER, c_szRegPath, false);
sApp = reg.GetString( c_szExecApp);
sArgs = reg.GetString( c_szExecArgs);
sDir = reg.GetString( c_szExecDir);
dwProcessId = reg.GetDword( c_szExecId);
}
void Params::Clear()
{
RegValue reg(HKEY_CURRENT_USER, c_szRegPath, true);
reg.Delete( c_szExecApp);
reg.Delete( c_szExecArgs);
reg.Delete( c_szExecDir);
reg.Delete( c_szExecId);
}