I recreated the code in C, compiled with tdm-gcc 4.8.1. Surprisingly, CreateDirectory() works even without Administrator rights, and fopen() only works with Administrator rights switched on, which is weird. The version of CreateDirectory() in A8's windows.h refuses to create any file in the system drive (but it works on some other drive which is not system drive, or in work_dir).

Here's the equivalent C code
Code:
#include <stdio.h>
#include <windows.h>

const char *token = "W\n";

bool IsElevated ();

int main() {
	printf("Administrator rights = %i",IsElevated());
	return 0;
}


bool IsElevated () {
	int dlen = 384, rlen = 3;
	char drivedir[384], cdir[3];
	GetSystemDirectory( drivedir, dlen );
	strcpy(drivedir, strtok(drivedir, token ));
	sprintf(cdir, "%i", rand()%1000 );
	strcat(drivedir,cdir);
	/*
	(0 != CreateDirectory(drivedir, 0)) // success
	return true;
	else return false;
	*/
	if(!fopen(drivedir,"w"))
	return false;
	else return true;
}



I'm confused... frown

Last edited by Scifi; 04/12/15 04:33.