home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
prfres.zip
/
PRFRESET.C
< prev
next >
Wrap
Text File
|
1993-06-15
|
3KB
|
125 lines
#define INCL_WIN
//#define INCL_WINSHELLDATA
#include <os2.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
main(int argc, char *argv[], char *envp[])
{
int iRC = 0;
HAB hab = (HAB)NULL;
PRFPROFILE prf;
FILE *pfTest;
BOOL fbQuery;
// at least on arg required
if ( argc < 2) {
printf( "Usage : %s (new_user_profile | ?)\n",
argv[ 0]);
return( 1);
} /* endif */
// check whether simply a query
if ( strcmp( argv[ 1], "?") != 0) {
// NO
fbQuery = FALSE;
// test whether file exists
if ( ( pfTest = fopen( argv[ 1], "r")) != (FILE *)NULL) {
fclose( pfTest);
} else {
printf( "new_user_profile does NOT exist\n");
return( 1);
} /* endif */
} else {
fbQuery = TRUE;
} /* endif */
// RC == 2 :=> API error
iRC = 2;
// get a HAB
if ( ( hab = WinInitialize( 0)) == (HAB)NULL) {
printf( "Error WinInitialize\n");
return( iRC);
} /* endif */
// init structure
prf.cchUserName = 0L;
prf.pszUserName = (PSZ)NULL;
prf.cchSysName = 0L;
prf.pszSysName = (PSZ)NULL;
// 1st query, get bufferlength
if ( PrfQueryProfile( hab, &prf)) {
if ( prf.cchUserName > 0L && prf.cchSysName > 0L) {
// allocate buffers
prf.pszUserName = (PSZ)malloc( (size_t)prf.cchUserName);
prf.pszSysName = (PSZ)malloc( (size_t)prf.cchSysName);
if ( prf.pszUserName != (PSZ)NULL && prf.pszSysName != (PSZ)NULL) {
// now query the actual names
if ( PrfQueryProfile( hab, &prf)) {
printf( "current user profile : %s\n"
"current system profile : %s\n",
prf.pszUserName,
prf.pszSysName);
if ( !fbQuery) {
// set user profile buffer to arg
prf.pszUserName = argv[ 1];
prf.cchUserName = (ULONG)( strlen( argv[ 1]) + 1);
// do a reset
if ( PrfReset( hab, &prf)) {
// and confirm the reset
if ( PrfQueryProfile( hab, &prf)) {
printf( "user profile set to : %s\n",
prf.pszUserName);
} else {
printf( "Error PrfQueryProfile (3)\n");
} /* endif */
iRC = 0;
} else {
printf( "Error PrfReset\n");
} /* endif */
} else {
iRC = 0;
} /* endif */
} else {
printf( "Error PrfQueryProfile (2)\n");
} /* endif */
} else {
printf( "Error malloc\n");
} /* endif */
} else {
printf( "Invalid buffer size : cchUserName = %lu, cchSysName = %lu\n",
prf.cchUserName,
prf.cchSysName);
} /* endif */
} else {
printf( "Error PrfQueryProfile (1)\n");
} /* endif */
WinTerminate( hab);
return( iRC);
}