import a reg key using CreateProcess & regedit.exe? - createprocess

i just need a simple way to import a .reg key into the registery hive
how can i do this?
my current code looks like this:
#include<Windows.h>
int main()
{
STARTUPINFO STARTINFO = { sizeof(STARTUPINFO) };
STARTINFO.cb = sizeof(STARTINFO);
STARTINFO.dwFlags = STARTF_USESHOWWINDOW;
STARTINFO.wShowWindow = SW_HIDE;
PROCESS_INFORMATION ProcessInfo;
CreateProcess("regedit.exe /S C:\\folder\\dd.reg", NULL , NULL, NULL, FALSE, CREATE_NO_WINDOW , NULL, NULL, &STARTINFO, &ProcessInfo);
from the commmand line C:\\Windows\regedit.exe /S C:\\folder\\dd.regworks perfectly fine, what i am doing wrong?
PS: i dont want to use system

Read the documentation for CreateProcess. The first parameter is just the name/path of the executable; the second one is the command line.
CreateProcess(L"regedit.exe", L"/S whatever.reg", ...)

Related

How to get Line numbers where content added, deleted or modified in svnlook ? (hooking)

I have created pre-commit hook and post-commit hook for visualSVN using c# for windows, but in pre-commit hook I also required to get the line numbers for each updated file where content got changed (added, deleted or modified.).
e.g.
content of output.cs (in last revision):
private static string GetSvnLookOutput(string repos, string txn, string subcommand)
{
var processStartInfo = new ProcessStartInfo
{
FileName = "svnlook.exe",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = String.Format("{0} -t \"{1}\" \"{2}\"", subcommand, txn, repos)
};
var process = Process.Start(processStartInfo);
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}
content of output.cs (in last revision):
private static string GetSvnLookOutput(string repos, string txn, string subcommand)
{
var processStartInfo = new ProcessStartInfo
{
FileName = "svnlook.exe",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = false, // modified the value
RedirectStandardError = false,// modified the value
Arguments = String.Format("{0} -t \"{1}\" \"{2}\"", subcommand, txn, repos)
};
var process = Process.Start(processStartInfo);// deleted one line after this line
process.WaitForExit();
return output;
}
I need know the line number (8,9,14) as output in the pre-commit hook.
For the pre-commit hooking through c# I followed this link .
NOTE : My end requirement is to find out the which function (in .cs file - with one class only) get modified.
Do you really need a hook script? It seems to me that the web interface of VisualSVN Server has the feature you need.
Revision log viewer shows changed line numbers and you can also share a link to a specific line. Here is an example on the demo server:
You can also use an advanced blame viewer. Here is an example on the demo server:

Two threads with two executables (.dis) files Limbo(Programming Language)

Can not understand how to do two processes (process 1 and 2) are implemented separately executable files and exchange messages. Something like (1.Hello 2.Hi 1.How are you ? ...).
The code below illustrates how the two threads exchanging messages from text files.
Necessary that instead of text files become executable files (.dis) that communicate with each other messages.
implement LThread;
include "sys.m";
include "bufio.m";
include "draw.m";
sys:Sys;
FD: import Sys;
stOut: ref Sys->FD;
bufio:Bufio;
Iobuf:import bufio;
LThread:module{
init: fn(nil: ref Draw->Context, nil: list of string);
process: fn(pName: string);
};
init(nil: ref Draw->Context, nil: list of string) {
sys=load Sys Sys->PATH;
bufio=load Bufio Bufio->PATH;
spawn process("processA.txt");
sys->sleep(10);
spawn process("processB.txt");
}
process(pName: string) {
file_buf:ref Iobuf;
file_buf = bufio->open(pName, sys->ORDWR);
temp_line:string;
temp_line=" ";
while (temp_line != nil){
temp_line=file_buf.gets('\n');
sys->sleep(200);
sys->print("%s \n",temp_line);
}
}
Perhaps with the help of modules, i do not know.
I found what I wanted. Its own interface has the type of a Command module, and that is the type of the things it executes.
On lines of exec, cmd is set to the first of the words in the argument list, and the string .dis is concatenated to it (to account for the fact that Limbo object program files are conventionally named using this suffix).
information was taken: "The Limbo Programming Language".
exec(ctx: ref Draw->Context, args: list of string){
c: Command;
cmd,file: string;
cmd = hd args;
file = cmd + ".dis";
c = load Command file;
if(c == nil)
c = load Command "/dis/"+file;
if(c == nil) {
sys->print("%s: not found\n", cmd);
return;
}
c->init(ctx, args);
}

Read file metadata via Windows Search from MFC program

I would like to read metadata of a DWG/AutoCAD file via Windows Search indexing service. I'm talking about properties that can be accessed with the right click in explorer without opening AutoCAD.
I have an MFC dialog based application written in Visual C++ 2005 and from inside this app I would like to access metadata (such as author, creation date etc.) of the given file. This was done by iFilter but it is deprecated since Windows XP and will be gone in Windows 8 (and LoadIFilter is not present in VS2005). Now from what I understand, it can be done with windows search - correct me if I'm wrong. Every example I found (msdn included) shows how to give data about your own files to windows search for indexing though. What I need is to know how to ask Windows Search about metadata for a given file.
Thanks
t.g.wilk
EDIT:
Here's what I've come up with so far:
BOOL WSQ_DoQuery( const wchar_t *constr, const wchar_t *querystr, VARIANT &result ) {
HRESULT hr = 0;
BOOL ret;
// Get the ADO connection
_Connection *con = NULL;
hr = CoCreateInstance( CLSID_Connection, NULL, CLSCTX_ALL, IID__Connection, (LPVOID *)&con );
if ( SUCCEEDED(hr) ) {
_Recordset *rs = NULL;
// Convert wide strings to BSTR as required by ADO APIs
BSTR bconstr = SysAllocString( constr );
BSTR bquerystr = SysAllocString( querystr );
if ( bconstr && bquerystr ) {
// Open the connection
hr = con->Open( bconstr, NULL, NULL, 0 );
if ( SUCCEEDED(hr) ) {
// Execute the query
hr = con->Execute( bquerystr, NULL, 0, &rs );
if ( SUCCEEDED(hr) ) {
// Display the results
ret = WSQ_GetCDate( rs ,result);
rs->Release();
} else {
TRACE( "Failed to execute query, %08x\r\n", hr );
} // if
} else {
TRACE( "Failed to open ADO connection, %08x\r\n", hr );
} // if
} else {
TRACE("Failed to convert wide to BSTR\r\n" );
} // if
con->Release();
if ( bconstr ) {
SysFreeString( bconstr );
}
if ( bquerystr ) {
SysFreeString( bquerystr );
}
} else {
TRACE("Failed to get connection, %08x\r\n", hr );
} // if
return ret;
} // DoQuery
The connection string (constr) is
provider=Search.CollatorDSO.1;EXTENDED PROPERTIES="Application=Windows"
as returned by ISearchQueryHelper.
And the query (querystr) is
SELECT System.Document.DateCreated FROM SystemIndex WHERE System.FileName LIKE 'filename%' AND DIRECTORY='file:C:\path\to\file'
The problem now is that I get an exception:
First-chance exception at 0x77c5fc56 in fraudTest.exe: Microsoft C++ exception: CNLBaseException at memory location 0x0012d6d0..
on this line
hr = con->Open( bconstr, NULL, NULL, 0 );
followed by the empty result from the query (this code is from WSQ_GetCDate):
rs->get_EOF( &eor );
while ( eor != VARIANT_TRUE ) { //this never executes }
Suprisingly SUCCEEDED(hr) returns true after the exception.
Where have I made en error and how to try and find it?
Thanks
t.g.wilk
I didn't solve this particular problem, but I learned that I don't need Windows Search to get the file metadata. The keyword to look for is "properties" instead of meta-data. I got my piece of code from Windows SDK v7.0 sample application named PropertyEdit.

Does AceFlags behavior changes with OS?

My utility extracts ACL from a directory & adds it to another. My issue is this -
While iterating through ACEs, I found that for ACEs with AceFlags value = 0, inherit flags (Applied To) is "Folder, subfolders & directories". When I apply the same ACL to another directory, in Windows 7 it works fine. However, in Windows XP, the inherit flags changes to "Folder only". Here is the code -
BOOL SetNonInheritedAceToTarget(LPWSTR pszSource, LPWSTR pszDestination)
{
BOOL bRetVal = FALSE;
DWORD dwRes = 0;
PSECURITY_DESCRIPTOR pSD = NULL;
PACL pacl = NULL;
if( ERROR_SUCCESS == GetNamedSecurityInfo(pszSource, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &pacl, NULL, &pSD) )
{
if(pacl)
{
for (USHORT i = 0; i < pacl->AceCount; i++)
{
ACCESS_DENIED_ACE * PACE = NULL;
if (!GetAce(pacl, i,(LPVOID*) &PACE))
continue;
if(PACE->Header.AceFlags & INHERIT_ONLY_ACE || PACE->Header.AceFlags & INHERITED_ACE)
{
// Delete the ACE
if(!DeleteAce(pacl, i))
{
TCHAR szErrorMsg[300] = {0};
wsprintf(szErrorMsg, L"Unable to delete ACE from DACL of = %ls", pszSource);
OutputDebugString(szErrorMsg);
}
}
}
}
}
if(ERROR_SUCCESS == SetNamedSecurityInfo(pszDestination, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, NULL, NULL, pacl, NULL))
bRetVal = TRUE;
return bRetVal;
}
I don't know if I am messing up with the code or is it really OS related issue. Help!!!. Again, if it is OS related issue, what do recommend, should I assign AceFlag manually?
--
Varun
Yes, ACE have changed with the arrival of Vista, mainly because of the integration of Integrity Level - previously called Integrity Control (IL). You must manually take care of these when your code must run on Windows 7 AND XP.
Oh... Silly me. I was checking INHERIT_ONLY_ACE to see it the ACE is inhereted... Any ways, as Mox pointed out, with vista (and above), new ACEs have been added to enhance integrity check in windows based objects. However, this does not change the way ACEs are interpreted. My code is fine, I was just checking an extra flag.
Thanks Mox for educating me.
--
Varun

How to use CreateProcessWithLogonW in c++?

Below is my code. The function is called, but it does not work. It dont call the exe. Why?
int Createprocesslogon()
{
STARTUPINFOW su_info;
ZeroMemory(&su_info, sizeof(STARTUPINFOW));
su_info.cb = sizeof(STARTUPINFOW);
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
CreateProcessWithLogonW(L"xxx", L"localhost", L"123456", 0, L"C:\\Program Files\\app\\IECapt.exe" ,L" --url=http://www.facebook.com/ --out=test.png --min-width=1024", 0, NULL, NULL, &su_info, &pi);
cout << "testt";
return 0;
}
Did you mean CreateProcessAsUser, or CreateProcessWithToken after a call to LogonUser?
EDIT:
Try this (embedding argument in one):
CreateProcessWithLogonW(L"xxx", L"localhost", L"123456", 0, 0,
L"\"C:\\Program Files\\app\\IECapt.exe\" \" --url=http://www.facebook.com/ --out=test.png --min-width=1024\"", 0, NULL, NULL, &su_info, &pi);
lpCommandLine is supposed to be the entire command line, starting with the executable (properly quoted). Otherwise your first argument ends up in argv[0] and is ignored by the program.

Resources