int wmain(int argc, WCHAR* argv[]) { if ((argc == 1) || ((argc == 2) && (lstrcmpi(argv[1], L"/?") == 0))) { ShowUsage(); return E_INVALIDARG; } int i = argc - 1; //File name is always the last option LPCWSTR szFilePath = argv[i]; //Find whether the file is a .exe or a .dll LPCWSTR szExtension = PathFindExtension(szFilePath); bool bExe = false; bool bCurrentUser = false; bool bUnregister = false; if (lstrcmpi(szExtension, TEXT(".exe")) == 0) bExe = true; //else default to dll //Parse the command line to find the other options i--; while(i > 0) { if (lstrcmpi(argv[i], L"/u") == 0) bUnregister = true; else if (lstrcmpi(argv[i], L"/c") == 0) bCurrentUser = true; // else // { // //Ignore the option // } i--; } HRESULT hr; if (bExe) { hr = RegisterExe(szFilePath, bUnregister, bCurrentUser); } else { hr = RegisterDll(szFilePath, bUnregister, bCurrentUser); } if (FAILED(hr)) ShowErrorMessage(hr); return hr; }
int wmain(int argc, WCHAR* argv[]) { int i, res, ret = 0; BOOL CallRegister = TRUE; BOOL CallInstall = FALSE; BOOL Unregister = FALSE; BOOL DllFound = FALSE; WCHAR* wsCommandLine = NULL; WCHAR EmptyLine[1] = {0}; OleInitialize(NULL); /* We mirror the Microsoft version by processing all of the flags before * the files (e.g. regsvr32 file1 /s file2 is silent even for file1). * * Note the complication that this version may be passed Unix format filenames * which could be mistaken for flags. The Windows version conveniently * requires each flag to be separate (e.g. no /su), so we will simply * assume that anything longer than /. is a filename. */ for(i = 1; i < argc; i++) { if (argv[i][0] == '/' || argv[i][0] == '-') { if (!argv[i][1]) return INVALID_ARG; if (argv[i][2] && argv[i][2] != ':') continue; switch (tolowerW(argv[i][1])) { case 'u': Unregister = TRUE; break; case 's': Silent = TRUE; break; case 'i': CallInstall = TRUE; wsCommandLine = parse_command_line(argv[i] + 2); /* argv[i] + strlen("/i") */ if (!wsCommandLine) wsCommandLine = EmptyLine; break; case 'n': CallRegister = FALSE; break; case 'c': /* console output */; break; default: output_write(STRING_UNRECOGNIZED_SWITCH, argv[i]); output_write(STRING_USAGE); return INVALID_ARG; } argv[i] = NULL; } } if (!CallInstall && !CallRegister) /* flags: /n or /u /n */ return INVALID_ARG; for (i = 1; i < argc; i++) { if (argv[i]) { WCHAR *DllName = argv[i]; res = 0; DllFound = TRUE; if (CallInstall && Unregister) res = InstallDll(!Unregister, DllName, wsCommandLine); /* The Windows version stops processing the current file on the first error. */ if (res) { ret = res; continue; } if (!CallInstall || (CallInstall && CallRegister)) { if(Unregister) res = UnregisterDll(DllName); else res = RegisterDll(DllName); } if (res) { ret = res; continue; } if (CallInstall && !Unregister) res = InstallDll(!Unregister, DllName, wsCommandLine); if (res) { ret = res; continue; } } } if (!DllFound) { output_write(STRING_HEADER); output_write(STRING_USAGE); return INVALID_ARG; } OleUninitialize(); /* return the most recent error code, even if later DLLs succeed */ return ret; }