????? ????? ???? ???? SA ???? ??? ????? SQL Server 2000 Desktop Engine (MSDE 2000)

?????? ????????? ?????? ?????????
???? ???????: 814463 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

??????

???? ??? ??????? ????? ????? ???? ???? sa ????? ??? ????? SQL Server Desktop Engine (???? ????? MSDE 2000).

??????? ????

??? ????? ???? ???? ???? ???? sa ????? ????? ?? ???? SQL Server 2000 Desktop Engine (MSDE 2000). ??? ????? ??? ??? ??? ??? ?????? ?????? ??? ?????? Windows. ?? ???? ??????? ???? sa ??? ?? ?????? ??? ??????? ?? ??? ?????? Windows; ??? ???? ???? ??????? ?????? ???? ??? ??? "??? ??????" ????? ???? sa ???? ???.

??? ??? ???? sa ???? ???? ????? ? ????? ?? ???? ?? ?????? ??? ??????? ???? MSDE 2000 ??? "??? ??????" ? ???? ?????? ???? MSDE ?? ?????? ?????????? ??? ????????. ????? ???? sa ?? ??? ????? ????? ???????? ???? ???? ???? ???????? ??? ????? ?????? ??? ?????? ??. ?? ?? ???????? ???? ??????? ??? ??? ???? MSDE 2000 ???????? ???? sa ?? ?????? ?????? ??? ??? ?????? ?? MSDE ?? ???? ?????? ??? ?????? ??? ??? ????? ??? ???? ???? MSDE. ???? ???? MSDE ???? ??????? ???? ?????? ??????? LocalSystem.

????? ?? ????????? ??? ????? ???? ???? ?? ?????? ???? Microsoft ?????? ??? ?????:

Security Rules

????? ??????? ??? ????? ???? ????? MSDE. ??? ?? ????????? ???????? ??????? ?????? ???? ??????? ??????? ?????? ???? ???? sa:
  • ??? ??? ???????? ?? ???????? ??? ????? MSDE ?? "??? ??????" ?? ??? ??????? ???? sa ? ??? ???? ???? ????? ???? sa ?? ????????. ??????? ???? ?????? ?? MSDE ?????? ???????.
  • ??? ?? ??? ??????? ???? sa ????? ????? ??????? ??? ?? ????? ??? ??????? ????? ???? sa ??? ??????? MSDE.

???????? ?? ????? ?????? ??? ??? ?????? ??? ?????? sa ??????? ?? ??????? ?????? ?? ??? Setup.ini ?? ???? ??????? ??????? ?? ??? ????? (.cmd) ?? ????? ??????? ?? ??? MSI ?? ??? ????? ???? ???? ??? ???? ?????? ??? ????. ???? ?????? ??? ?? ???? ????? ???????? ?????? ?????? ????? ????? ?? ??? ??????? ??? ??? ??? ?? ???? ??? ????? ??????? MSDE ????? ????? ???????:
  • ????? setup.exe MSDE ?? ????????? ???????? ????? ??????? ?? ??? ???? SAPWD ?? ???????.

    ??? ???? ??????? ????? ?????? ??????? ?? ???? ??????? ???.NET Framework ?????? ??? ?? ????? SAPWD ?? ??????? ?????? ProcessStartInfo ?? ????? ?????? ??????? ???????? ?????? Win32 CreateProcess ???? SAPWD ?? ??????? lpCommandLine.


    ????? ?? ????????? ??? ????? ??? ????? SAPWD ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
    810826???? ??????? ??????? ?? ?????? MSDE ????? Service Pack 2
  • ????? ????? ???? ?????? ???? ???? ????? ??? ??????? ??????? ??????? ??? MSDE ?? ????? ???? ????? ??? Windows Installer.

?????? ?? ???? ????? ???? ???? ???? sa ????? ??????? MSDE 2000 ???????? Windows "??? ??????". ?? ??? ?????????? ??? ???? ????? ???? ?????? ??? ?????? ???????. ???? Microsoft ???? ??????? ???? ????? ????? ?????? ????? MSDE 2000.

????? ??????? ???? Microsoft ?? ??????? ?????? ???? ???? ?????? ??????? ????? ????? API ???:
  • CryptAcquireContext
  • CryptGenRandom
  • CryptCreateHash
  • CryptHashData
?? ???? ??????? ?????? ?????? ????? ??????? CryptReleaseContext.

?? ???? ??????? ??????? ?????? ??? ??????? ?????? System.Security.Cryptography.RNGCryptoServiceProvider ?????? ??? ????? ????? ?????? ?? ?? ????? ?????? ???? ?? ??????? ?????? ??????? ??????? ComputeHash ??? System.Security.Cryptography.SHA1. ??? ?? ???? ????? ??????? ?? ????? ????? ??? 7 ? 20 ???.

??? ???? ???? ?????? ' sa ' ? ?? ??? ?? ???? ?? ???? ?????? sa ????? ?????? ??? "??? ??????" ? ???? ????? ??? ????? ?????? ?????? ???? ????? ????? ???? ?????? sa ???? ????? ???? ?????? ???????. ?????????? ???? ???? ?????????? ????? ?? ????? ?????? "?????????" ???????? ????? ??? sysadmin. ???? ????? ???? MSDE ?? ??? ?????? Windows ??? "??? ??????" ?? ????? ?????? ????? ??? sysadmin ? ???? ????? ???? ?????? sa. ??? ?? ?????? ????? ???????? ?? ????? ??? ????? ?????? ????????? ?? ??? ????? ??????.

????? ?? ????????? ??? ????? ????? ?????? ????????? ?? ??? ????? ?????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
263712????? impede ????????? Windows NT ?? ????? ???? SQL Server ?????? ????????


?????? ??? ???? ?? ????????? ??? ????? ???? ?????? ?????? sa ???? ? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
322336????? ?????? ?? ????? ???? ???? ????? ?????? ?? MSDE ?? SQL Server 2005 Express Edition

?????? ????? ???????? ????? ???? ?????? sa ????? ??????? ??????? ?? ??? ??????? ??? ??? ?????? ??????? ??????? MSDE.

??????? ??????? ??????? ????? ???????? ???????? ?????? ?????? ???? ???? sa ?????? ?? ?? ?????? ????? MSDE.

???????? Microsoft Visual C++ .NET

  1. ???? ??? ???? ? ???? ??? ???? ??????? ? ???? ??? Microsoft Visual Studio .NET ? ??? ??? ????? .NET Visual Studio ?? ???? ??? ???? ??????? .NET Visual Studio.
  2. ???? ???????.
  3. ?? ???? ???????? ???????? ??????? ?? "???????":: & # pragma
    #pragma once
    
    #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers.
    #define UNICODE
    #include <stdio.h>
    #include <windows.h>
    #include <wincrypt.h>
    
    #ifdef UNICODE
    	#define STRNCPY	wcsncpy
    #else
    	#define STRNCPY strncpy
    #endif
    
    #include <atlenc.h>
    
    #define SAPWDSWITCH _T("SAPWD=")
    #define INSTANCENAME _T("INSTANCENAME=MSDETEST")
    
    
    BOOL GenPwd(TCHAR*, int);
    void DisplayError (DWORD);
    
    int main(void)
    {	
    	//Generate random length for password, between 7 and 20 characters.
    	int nPwdLen = ((rand() % 20) + 7) + 1;	//Extra character for null terminator
    	TCHAR* pPwd = new TCHAR[nPwdLen];
    	UINT uRes = 0;
    	DWORD dwRes = 0;
    	if (!GenPwd(pPwd, nPwdLen))
    	{
    		//Failed to generate a password, log the error and return failure.
    		dwRes = GetLastError();
    		DisplayError(dwRes);
    
    		return dwRes;
    	}
    
    
            STARTUPINFO si;
            PROCESS_INFORMATION pi;
    
            ZeroMemory( &si, sizeof(si) );
            si.cb = sizeof(si);
            ZeroMemory( &pi, sizeof(pi) );
    
    	//Allocate a string for the command line.
    	LPTSTR lpCommand = new TCHAR[nPwdLen + _tcslen(INSTANCENAME) + _tcslen(SAPWDSWITCH) + 2];
    
    	_stprintf(lpCommand, _T("%s %s%s"),INSTANCENAME,  SAPWDSWITCH, pPwd);
    // Specify the complete path of Setup.exe.
    	if (!CreateProcess(_T("setup.exe"), lpCommand, NULL, NULL, FALSE, 
    				0, NULL, NULL, &si, &pi))
    	{
    		dwRes = GetLastError();
    		DisplayError(dwRes);
    	}
    	return 0;
    }
    
    
    //Generates a Random string of length nLen - 1.  Buffer ppwd must allocate an extra character for null terminator.
    //Returns TRUE if successful, FALSE if fails.
    //Extended error information can be obtained from GetLastError().
    BOOL GenPwd(TCHAR* ppwd, int nLen)
    {
    	BOOL bResult = FALSE;	//assume failure
    	HCRYPTPROV hProv = NULL;
    	HCRYPTHASH hHash = NULL;
    	
    	//Storage for random string 4 times longer than the resulting password.
    	DWORD dwBufSize = nLen*4;
    	DWORD dwSize = Base64EncodeGetRequiredLength((int)dwBufSize);
    	LPSTR pEncodedString = NULL;
    	LPBYTE pRandomBuf = NULL;
    	TCHAR* pTRandomPwd = NULL;
    	
    	try
    	{
    		pEncodedString = new char[dwSize];
    		pRandomBuf = new BYTE[dwBufSize];
    		
    		// Try to acquire context to Crypto provider.
    		if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_SILENT))
    		{
    			if (GetLastError() == NTE_BAD_KEYSET) //Test for non-existent keyset
    			{
    				if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_SILENT | CRYPT_NEWKEYSET))
    					throw(GetLastError());
    			}
    			else
    				throw(GetLastError());
    		}
    
    		//Generate a random sequence.
    		if (!CryptGenRandom(hProv, dwBufSize, pRandomBuf))
    		{
    			throw(GetLastError());
    		}
    
    		//Get a handle to a hash, then hash the random stream.
    		if (!CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash))
    		{
    			throw(GetLastError());
    		}
    
    		if (!CryptHashData(hHash, pRandomBuf, dwBufSize, NULL))
    		{
    			throw(GetLastError());
    		}
    	
    		//Destroy the hash object.
    		CryptDestroyHash(hHash);
    		//Release Provider context
    		CryptReleaseContext(hProv, 0);	
    	
    		//Encode the hash value to base64.
    		if (!Base64Encode(pRandomBuf, dwBufSize, pEncodedString, (int*) &dwSize, 0))
    		{
    			throw(GetLastError());
    		}
    	
    		//Determine how many tchars you need to convert string to base64.
    		int nTchars = (int) strlen(pEncodedString);
    	
    		pTRandomPwd = new TCHAR[nTchars];
    	
    #ifdef UNICODE
    		if (MultiByteToWideChar(CP_UTF8, 0, pEncodedString, nTchars, pTRandomPwd, nTchars) == 0)
    		{
    			throw(GetLastError());
    		}
    #else
    		STRNCPY( pTRandomPwd, pEncodedString, nLen);
    #endif
    
    		//Copy the first x characters of random string to output buffer.
    		STRNCPY(ppwd, pTRandomPwd, nLen);
    		//Add null terminator to ppwd string.
    		ppwd[nLen] = _T('\0');
    
    		bResult = TRUE;
    
    	}
    	catch (DWORD)
    	{
    		//Set return value to false.
    		bResult = FALSE;
    	}
    	catch (...)
    	{
    		//Unknown error, throw. 
    		throw;
    	}
    
    	//Clean up memory.
    	if (pRandomBuf)
    	{
    		delete pRandomBuf;
    		pRandomBuf = NULL;
    	}
    
    	if (pEncodedString)
    	{
    		delete pEncodedString;
    		pEncodedString = NULL;
    	}
    
    	if (pTRandomPwd)
    	{
    		delete pTRandomPwd;
    		pTRandomPwd = NULL;
    	}
    
    	return bResult;
    }
    
    
    void DisplayError (DWORD dwError)
    {
    	//Resolve the error code to a message string.
    	LPCTSTR MessageBuffer;
    	DWORD dwBufferLength = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
    		NULL, // module to get message from (NULL == system)
    		dwError,
    		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language.
    		(LPTSTR) &MessageBuffer,
    		0,
    		NULL
    		);
    
    	DWORD dwBytesWritten;
    	// Output message string on stderr.
    	WriteFile(
    		GetStdHandle(STD_ERROR_HANDLE),
    		MessageBuffer,
    		dwBufferLength,
    		&dwBytesWritten,
    		NULL
    		);
    }
    
  4. ?? ???? ????? ???? StrongSA.cpp.
  5. ?? ???? ???????? ???? ????? ?????? ????? ????????? ????????:

    strongSA.cpp cl
  6. ?? ???? ???????? ???? ????? ?????? ?????? ????????? ????????:

    strongSA.exe

???????? Microsoft C# .NET

  1. ?? Visual Studio .NET ? ????? ???? Visual C# "????" ??????? ???????.
  2. ?? ???? ???????? ???????? ??????? ?? ??? ??? ???? ????? ??? ?????? ???????.

    ???? ?? ?? ???????? ???????? ??? ??? ???? ????????? ???????? ???????? ?? file:
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Resources;
    using Microsoft.Win32;
    using System.Security.Cryptography;
    
    
    class InstMSDE
    {
    	static void Main(string[] args)
    	{
    		try
    		{   
    			
    
    			// Generate random password.
    			RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
    			byte[] encodedSeed = new byte[512];
    			rng.GetBytes(encodedSeed);
    			SHA1 sha1 = SHA1.Create();
    			byte[] hashval = sha1.ComputeHash(encodedSeed);
    			String base64HashVal = Convert.ToBase64String(hashval);
    			// Trim "=" off the end.
    			base64HashVal = base64HashVal.TrimEnd('=');
    				
    			string msdeINI = "setup.ini";
    
    			// You have to set startInfo parameters values as appropriate for your installation.
    			ProcessStartInfo startInfo = new ProcessStartInfo();
    
    			// Setup.exe for MSDE sp3.
    			startInfo.FileName = "setup.exe"; 
    
    			// Pass the SA password to the setup program.
    			startInfo.Arguments = "/settings \"" + msdeINI + "\"" + " SAPWD=" + base64HashVal + " /qr+ "; 
    			startInfo.WindowStyle = ProcessWindowStyle.Normal;
    			// Substitute the workdir with complete path of installation folder. 
    			startInfo.WorkingDirectory = "c:\\Workingdir";
    				
    			Process.Start(startInfo);
    			
    			
    		}
    		catch (Exception e)
    		{
    			Console.WriteLine("Unable to execute program due to the following error: " + e.Message);
    			return;
    		}  
    	}
    }
    
  3. ???? F5 ????? ?? ?? ?????? ????????.

?????

????? ?? ????????? ??? ????? ????? MSDE ?? ????? ????? ???? ?? ?????? ???? Microsoft ?????? ??? ?????:
Embedding MSDE 2000 Setup in the Setup of Custom Applications

???????

???? ???????: 814463 - ????? ??? ??????: 03/???? ?????/1428 - ??????: 1.5
????? ???
  • Microsoft SQL Server 2000 Desktop Engine (Windows)
????? ??????: 
kbmt kbsetup kbsecurity kblogin kbauthentication kbsample kbguidelines kbcode kbinfo KB814463 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????814463
????? ??????? ?? ????? ???? ?? ????? ???????
?? ????? ????? ?????? ???? ???? ???? ??? ??????? ??? ?? ? ?? ??? ??????? Microsoft ??? ????? ??? ??????? ????? ?????? ?????

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com