home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / utils / homedrv / homedrv.c next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  3.3 KB  |  98 lines

  1. #define STRICT
  2. #define _UNICODE
  3. #define UNICODE 
  4.  
  5. #include <windows.h>
  6. #include <tchar.h>
  7. #include <wchar.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <lm.h> 
  12.  
  13.  
  14. /****************************************************************************\
  15. *
  16. * FUNCTION: Main
  17. *
  18. \****************************************************************************/
  19.  
  20. int main()
  21. {
  22. LPTSTR CommandLine, CommandName, ServerName, UserName, HomeDrive, ChPass;
  23. USER_INFO_3 UserInfo;
  24. DWORD ComOK, ResetPassword;
  25. USER_INFO_3 *InfoPointer;
  26. LPBYTE *Pointer;
  27.  
  28. CommandName=(LPTSTR) calloc(1024,sizeof(TCHAR));
  29. UserName=CommandName+128;
  30. HomeDrive=UserName+128;
  31. ServerName=HomeDrive+128;
  32. ChPass=ServerName+129;
  33. wprintf(L"\nHome drive modification utility\n(c) Neil Ferguson, Linacre College, Oxford\n\n");
  34. CommandLine=GetCommandLine();
  35. swscanf(CommandLine,L"%s %s %s %s %s",CommandName, ServerName, UserName,HomeDrive, ChPass);
  36. ComOK=ResetPassword=0;
  37. if ((!wcscmp(ChPass,L"/p"))||(!wcscmp(ChPass,L"/P")))
  38.         ResetPassword=1;
  39. else if ((!wcscmp(HomeDrive,L"/p"))||(!wcscmp(HomeDrive,L"/P")))
  40.         {
  41.         ResetPassword=1;
  42.         HomeDrive[0]=0;
  43.         } 
  44. if((wcslen(ServerName)==0)||(wcslen(UserName)==0))
  45.         ComOK=1;
  46. else if(ServerName[0]!=TEXT('\\'))
  47.         {
  48.         ServerName--;ServerName[0]=TEXT('\\');
  49.         ServerName--;ServerName[0]=TEXT('\\');
  50.         }
  51. else if(ServerName[1]!=TEXT('\\'))
  52.         {
  53.         ServerName--;ServerName[0]=TEXT('\\');
  54.         }
  55. if (ComOK==0)
  56.         ComOK=NetUserGetInfo(ServerName,UserName,3,Pointer);
  57. if (ComOK==1)
  58.         wprintf(L"Usage:\tHOMEDRV ServerName UserName [HomeDrive] [/p]\n    (/p forces password change at next logon)\n");
  59. else if((ComOK==53)||(ComOK==123))
  60.         wprintf(L"Computer %s not found.\n",ServerName);
  61. else if(ComOK==2221)
  62.         wprintf(L"Username %s not defined on %s.\n",UserName,ServerName);
  63. else  if(ComOK!=0)
  64.         wprintf(L"The command terminated abnormally with error code %i\n",ComOK);
  65. else
  66.         {
  67.         InfoPointer=(USER_INFO_3 *) (*Pointer); 
  68.         UserInfo=*InfoPointer;
  69.         if (wcslen(HomeDrive)==0)
  70.                 {
  71.                 wprintf(L"Current home drive for %s on %s is %s\n",UserName,ServerName,UserInfo.usri3_home_dir_drive);
  72.                   }
  73.         if((wcslen(HomeDrive)>0)&&((wcslen(HomeDrive)>2)||(HomeDrive[1]!=TEXT(':'))||(! IsCharAlpha(HomeDrive[0]))))
  74.                 wprintf(L"Incorrectly specified drive letter.\n");
  75.         else
  76.                 {
  77.                 ComOK=CharUpperBuff(HomeDrive,1);
  78.                 if (ResetPassword)
  79.                         UserInfo.usri3_password_expired=1;
  80.                 if (wcslen(HomeDrive)>0)
  81.                         UserInfo.usri3_home_dir_drive=HomeDrive;
  82.                 ComOK=NetUserSetInfo(ServerName,UserName,3,(LPBYTE) (&UserInfo),NULL);
  83.                 if(ComOK==0)
  84.                         {
  85.                         if (wcslen(HomeDrive)>0)
  86.                                 wprintf(L"Home drive for %s successfully changed to %s on %s\n",UserName,HomeDrive,ServerName);
  87.                         if (ResetPassword)
  88.                                 wprintf(L"Account set so that %s must change password at next logon.\n",UserName);
  89.                         }
  90.                 else if(ComOK==2226)
  91.                         wprintf(L"Operation can only be performed on the primary domain controller\n");
  92.                 else
  93.                         wprintf(L"The command terminated abnormally with error code %i",ComOK);
  94.                 }
  95.         }
  96. return ComOK;
  97. }
  98.