Home All Groups Group Topic Archive Search About
Author
19 Sep 2005 3:08 PM
nospam
Here's a stupid question...VB6
Is there any way for me to declare a constant = a variable?
I need to declare a password string as a constant, but I have it
encrypted.  So when I decrypt the password, I want to set the Const
passwd equal to the decrypted password.
Thanks

Author
19 Sep 2005 3:38 PM
Ken Halter
<nospam@meatonconsulting.com> wrote in message
news:1127142517.330151.122110@z14g2000cwz.googlegroups.com...
> Here's a stupid question...VB6
> Is there any way for me to declare a constant = a variable?
> I need to declare a password string as a constant, but I have it
> encrypted.  So when I decrypt the password, I want to set the Const
> passwd equal to the decrypted password.
> Thanks
>

You can store the encrypted version as a constant... is that what you're
after? You can't assign a Const = Variable though.

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..
Author
19 Sep 2005 3:49 PM
Ralph
<nospam@meatonconsulting.com> wrote in message
news:1127142517.330151.122110@z14g2000cwz.googlegroups.com...
> Here's a stupid question...VB6
> Is there any way for me to declare a constant = a variable?
> I need to declare a password string as a constant, but I have it
> encrypted.  So when I decrypt the password, I want to set the Const
> passwd equal to the decrypted password.
> Thanks
>

No. You can't change the value of a 'constant'. (they are constant. <g>)

But I assume the reason you want to do this is so you have one value/name
that you can use throughout your program. One way is to create a global
object.

[Warning Air Code!]
' Class CPKey
Const cryptPassword = zx%3vb1T3@jj
Private mPassword As String 'local copy

Public Property Let Password(ByVal sPublicKey As String)
    If Len(sPublicKey) = 0 Then Exit Property
    mPassword = DecryptPassword( sPublicKey, cryptPassword  )
End Property
Public Property Get Password() As String
    Password = mPassword
End Property
' End Class

In code...
Dim CPK As CPKey: Set CPK = New CPKey
.....
CPK.Password = "publicKey"
....
CJunk.OpenSomething(CPK.Password)
Author
19 Sep 2005 3:53 PM
Mike D Sutton
> Here's a stupid question...VB6
> Is there any way for me to declare a constant = a variable?
> I need to declare a password string as a constant, but I have it
> encrypted.  So when I decrypt the password, I want to set the Const
> passwd equal to the decrypted password.

As others have said this is not possible since the value of a constant must be known at compile time.  In any case it's dangerous to
have the password floating about in plain-text, a much better technique is to store a hashed version of the password and compare
against that in the login process.  Have a look at this old post on the subject:
http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/msg/651bb4ca631d82f5
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
22 Sep 2005 2:36 PM
nospam
Thanks guys.  That should help me out
Author
23 Sep 2005 2:50 PM
nospam
Ok, I'm still having problems.  I have my constant declared using the
encrypted password.  I somehow need to decrypt the password and then
use it in another statement that needs a constant to run correctly.
Here is all of the code:

Public passwrd As String
Public encryptedpasswd As String
Private Const AdminUser = "refupdlocal"
Private Const AdminPwd = "EncryptedPassw0rd"
Public Passwd As String
Private Const LOGON_WITH_PROFILE As Long = &H1&
Private Const LOGON_NETCREDENTIALS_ONLY As Long = &H2&
Private Const WAIT_TIMEOUT = 258&
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

Private Type STARTUPINFOW
  cb As Long
  lpReserved As Long
  lpDesktop As Long
  lpTitle As Long
  dwX As Long
  dwY As Long
  dwXSize As Long
  dwYSize As Long
  dwXCountChars As Long
  dwYCountChars As Long
  dwFillAttribute As Long
  dwFlags As Long
  wShowWindow As Integer
  cbReserved2 As Integer
  lpReserved2 As Long
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
End Type

Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadId As Long
End Type

Private Declare Function GetCommandLine Lib "kernel32" Alias _
    "GetCommandLineA" () As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" ( _
    ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Private Declare Function GetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function CreateProcessWithLogonW Lib "advapi32" ( _
    ByVal lpUsername As Long, ByVal lpDomain As Long, _
    ByVal lpPassword As Long, ByVal dwLogonFlags As Long, _
    ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, _
    ByVal dwCreationFlags As Long, lpEnvironment As Any, _
    ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFOW, _
    lpProcessInfo As PROCESS_INFORMATION) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias _
    "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As
Long
Private Declare Function FormatMessage Lib "kernel32" Alias _
    "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, _
    ByVal dwMessageId As Long, ByVal dwLanguageId As Long, _
    ByVal lpBuffer As String, ByVal nSize As Long, _
    Arguments As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" ( _
    ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" ( _
    ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Private Function CommandLine() As String
    Dim lpStr As Long, i As Long
    Dim Buffer As String
    Dim cmdLine As String


    lpStr = GetCommandLine()
    Buffer = Space$(512)
    lstrcpy Buffer, lpStr
    Buffer = Left$(Buffer, InStr(Buffer & vbNullChar, vbNullChar) - 1)
    If Left$(Buffer, 1) = """" Then
        i = InStr(2, Buffer, """")
        cmdLine = LTrim$(Mid$(Buffer, i + 1))
    Else
        i = InStr(Buffer, " ")
        cmdLine = LTrim$(Mid$(Buffer, i))
    End If
    CommandLine = cmdLine
End Function


Function UserName() As String
    Dim lpBuffer As String
    Dim nSize As Long
    Dim lError As Long
    lpBuffer = Space(255)
    nSize = Len(lpBuffer)
    Call GetUserName(lpBuffer, nSize)
    UserName = Left(lpBuffer, InStr(1, lpBuffer, Chr(0)) - 1)
End Function


Private Function GetErrorMessage(Error As Long) As String
    Dim Buffer As String
    Dim lBuffer As Long
    Buffer = String(1024, 0)
    lBuffer = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&,
Error, _
        0, Buffer, 200, ByVal 0&)
    GetErrorMessage = Left(Buffer, lBuffer)
End Function


Private Function ComputerName() As String
    Dim lpBuffer As String
    Dim nSize As Long
    Dim lError As Long
    lpBuffer = Space(255)
    nSize = Len(lpBuffer)
    Call GetComputerName(lpBuffer, nSize)
    ComputerName = Left(lpBuffer, nSize)
End Function


Private Function RunAs(sUser As String, sPwd As String, _
    sCmdLine As String, Optional Parameters As String = "", _
    Optional Directory As String = "", _
    Optional WindowStyle As VbAppWinStyle = vbNormalFocus, _
    Optional Wait As Boolean = False, Optional Timeout As Long = -1, _
    Optional Terminate As Boolean = False, _
    Optional hProcess As Long) As Long
    Dim SInfo As STARTUPINFOW
    Dim PInfo As PROCESS_INFORMATION
    Dim aUser() As String
    Dim sDomain As String
    Dim sUsername As String
    Dim sDir As String
    Dim sCmd As String
    Dim Res As Long


    aUser = Split(sUser, "\")
    If UBound(aUser) = 1 Then
        sDomain = aUser(0)
        sUsername = aUser(1)
    Else
        sDomain = ComputerName
        sUsername = sUser
    End If


    SInfo.dwFlags = STARTF_USESHOWWINDOW
    SInfo.wShowWindow = WindowStyle


    If Directory = "" Then
        sDir = CurDir
    Else
        sDir = Directory
    End If


    If Parameters <> "" Then
        sCmd = sCmdLine & " " & Parameters
    Else
        sCmd = sCmdLine
    End If


    Res = CreateProcessWithLogonW(StrPtr(sUsername), StrPtr(sDomain), _
        StrPtr(sPwd), LOGON_WITH_PROFILE, 0&, StrPtr(sCmd), 0&, ByVal
0&, _
        StrPtr(sDir), SInfo, PInfo)


    If Res <> 0 Then
        hProcess = PInfo.hProcess
        If Wait Then
            If Timeout > 0 Then Timeout = Timeout * 1000
            If WaitForSingleObject(PInfo.hProcess, _
                Timeout) = WAIT_TIMEOUT Then
                RunAs = WAIT_TIMEOUT
                If Terminate Then
                    If TerminateProcess(PInfo.hProcess, 0) = 0 Then
                        RunAs = Err.LastDllError
                    End If
                End If
            End If
        End If
    Else
        RunAs = Err.LastDllError
        hProcess = 0
    End If
End Function


Sub Main()
    Dim Res As Long


    If LCase(UserName) <> LCase(AdminUser) Then
        Res = RunAs(AdminUser, AdminPwd, "JDSecure20.exe", _
            CommandLine)
        If Res <> 0 Then MsgBox GetErrorMessage(Res)
        Exit Sub
    End If
End Sub

Private Sub Form_Load()
Encrypt
Main
Unload Me
End Sub

Public Sub Encrypt()
Dim a(4) As Integer
Dim looper As Integer
Dim holdstr As String
a(1) = 25
a(2) = 67
a(3) = 44
a(4) = 101
looper = 1
For i = 1 To Len(AdminPwd)
  enc = Asc(Mid(AdminPwd, i, 1))
  newchar = Chr(enc Xor a(looper))
  holdstr = holdstr & newchar
  looper = looper + 1
  If looper = 5 Then looper = 1
Next i
End Sub
Author
23 Sep 2005 5:03 PM
Someone
What kind of problems you are having? What error message? What line the
error occurs on?

I noticed that some variables were not declared, and that means you are not
using "Option Explicit". You also have STARTF_USESHOWWINDOW undeclared, so
the outcome is uncertain when you make the API call. "Option Explicit" would
catch that sort of thing. Otherwise your code is fine, but I don't know if
Encrypt works correctly.


<nospam@meatonconsulting.com> wrote in message
Show quoteHide quote
news:1127487044.976564.239230@g14g2000cwa.googlegroups.com...
> Ok, I'm still having problems.  I have my constant declared using the
> encrypted password.  I somehow need to decrypt the password and then
> use it in another statement that needs a constant to run correctly.
> Here is all of the code:
>
> Public passwrd As String
> Public encryptedpasswd As String
> Private Const AdminUser = "refupdlocal"
> Private Const AdminPwd = "EncryptedPassw0rd"
> Public Passwd As String
> Private Const LOGON_WITH_PROFILE As Long = &H1&
> Private Const LOGON_NETCREDENTIALS_ONLY As Long = &H2&
> Private Const WAIT_TIMEOUT = 258&
> Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
>
> Private Type STARTUPINFOW
>  cb As Long
>  lpReserved As Long
>  lpDesktop As Long
>  lpTitle As Long
>  dwX As Long
>  dwY As Long
>  dwXSize As Long
>  dwYSize As Long
>  dwXCountChars As Long
>  dwYCountChars As Long
>  dwFillAttribute As Long
>  dwFlags As Long
>  wShowWindow As Integer
>  cbReserved2 As Integer
>  lpReserved2 As Long
>  hStdInput As Long
>  hStdOutput As Long
>  hStdError As Long
> End Type
>
> Private Type PROCESS_INFORMATION
>    hProcess As Long
>    hThread As Long
>    dwProcessId As Long
>    dwThreadId As Long
> End Type
>
> Private Declare Function GetCommandLine Lib "kernel32" Alias _
>    "GetCommandLineA" () As Long
> Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" ( _
>    ByVal lpString1 As String, ByVal lpString2 As Long) As Long
> Private Declare Function GetUserName Lib "advapi32.dll" Alias _
>    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
> Private Declare Function CreateProcessWithLogonW Lib "advapi32" ( _
>    ByVal lpUsername As Long, ByVal lpDomain As Long, _
>    ByVal lpPassword As Long, ByVal dwLogonFlags As Long, _
>    ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, _
>    ByVal dwCreationFlags As Long, lpEnvironment As Any, _
>    ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFOW, _
>    lpProcessInfo As PROCESS_INFORMATION) As Long
> Private Declare Function GetComputerName Lib "kernel32" Alias _
>    "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As
> Long
> Private Declare Function FormatMessage Lib "kernel32" Alias _
>    "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, _
>    ByVal dwMessageId As Long, ByVal dwLanguageId As Long, _
>    ByVal lpBuffer As String, ByVal nSize As Long, _
>    Arguments As Long) As Long
> Private Declare Function WaitForSingleObject Lib "kernel32" ( _
>    ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
> Private Declare Function TerminateProcess Lib "kernel32" ( _
>    ByVal hProcess As Long, ByVal uExitCode As Long) As Long
>
> Private Function CommandLine() As String
>    Dim lpStr As Long, i As Long
>    Dim Buffer As String
>    Dim cmdLine As String
>
>
>    lpStr = GetCommandLine()
>    Buffer = Space$(512)
>    lstrcpy Buffer, lpStr
>    Buffer = Left$(Buffer, InStr(Buffer & vbNullChar, vbNullChar) - 1)
>    If Left$(Buffer, 1) = """" Then
>        i = InStr(2, Buffer, """")
>        cmdLine = LTrim$(Mid$(Buffer, i + 1))
>    Else
>        i = InStr(Buffer, " ")
>        cmdLine = LTrim$(Mid$(Buffer, i))
>    End If
>    CommandLine = cmdLine
> End Function
>
>
> Function UserName() As String
>    Dim lpBuffer As String
>    Dim nSize As Long
>    Dim lError As Long
>    lpBuffer = Space(255)
>    nSize = Len(lpBuffer)
>    Call GetUserName(lpBuffer, nSize)
>    UserName = Left(lpBuffer, InStr(1, lpBuffer, Chr(0)) - 1)
> End Function
>
>
> Private Function GetErrorMessage(Error As Long) As String
>    Dim Buffer As String
>    Dim lBuffer As Long
>    Buffer = String(1024, 0)
>    lBuffer = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&,
> Error, _
>        0, Buffer, 200, ByVal 0&)
>    GetErrorMessage = Left(Buffer, lBuffer)
> End Function
>
>
> Private Function ComputerName() As String
>    Dim lpBuffer As String
>    Dim nSize As Long
>    Dim lError As Long
>    lpBuffer = Space(255)
>    nSize = Len(lpBuffer)
>    Call GetComputerName(lpBuffer, nSize)
>    ComputerName = Left(lpBuffer, nSize)
> End Function
>
>
> Private Function RunAs(sUser As String, sPwd As String, _
>    sCmdLine As String, Optional Parameters As String = "", _
>    Optional Directory As String = "", _
>    Optional WindowStyle As VbAppWinStyle = vbNormalFocus, _
>    Optional Wait As Boolean = False, Optional Timeout As Long = -1, _
>    Optional Terminate As Boolean = False, _
>    Optional hProcess As Long) As Long
>    Dim SInfo As STARTUPINFOW
>    Dim PInfo As PROCESS_INFORMATION
>    Dim aUser() As String
>    Dim sDomain As String
>    Dim sUsername As String
>    Dim sDir As String
>    Dim sCmd As String
>    Dim Res As Long
>
>
>    aUser = Split(sUser, "\")
>    If UBound(aUser) = 1 Then
>        sDomain = aUser(0)
>        sUsername = aUser(1)
>    Else
>        sDomain = ComputerName
>        sUsername = sUser
>    End If
>
>
>    SInfo.dwFlags = STARTF_USESHOWWINDOW
>    SInfo.wShowWindow = WindowStyle
>
>
>    If Directory = "" Then
>        sDir = CurDir
>    Else
>        sDir = Directory
>    End If
>
>
>    If Parameters <> "" Then
>        sCmd = sCmdLine & " " & Parameters
>    Else
>        sCmd = sCmdLine
>    End If
>
>
>    Res = CreateProcessWithLogonW(StrPtr(sUsername), StrPtr(sDomain), _
>        StrPtr(sPwd), LOGON_WITH_PROFILE, 0&, StrPtr(sCmd), 0&, ByVal
> 0&, _
>        StrPtr(sDir), SInfo, PInfo)
>
>
>    If Res <> 0 Then
>        hProcess = PInfo.hProcess
>        If Wait Then
>            If Timeout > 0 Then Timeout = Timeout * 1000
>            If WaitForSingleObject(PInfo.hProcess, _
>                Timeout) = WAIT_TIMEOUT Then
>                RunAs = WAIT_TIMEOUT
>                If Terminate Then
>                    If TerminateProcess(PInfo.hProcess, 0) = 0 Then
>                        RunAs = Err.LastDllError
>                    End If
>                End If
>            End If
>        End If
>    Else
>        RunAs = Err.LastDllError
>        hProcess = 0
>    End If
> End Function
>
>
> Sub Main()
>    Dim Res As Long
>
>
>    If LCase(UserName) <> LCase(AdminUser) Then
>        Res = RunAs(AdminUser, AdminPwd, "JDSecure20.exe", _
>            CommandLine)
>        If Res <> 0 Then MsgBox GetErrorMessage(Res)
>        Exit Sub
>    End If
> End Sub
>
> Private Sub Form_Load()
> Encrypt
> Main
> Unload Me
> End Sub
>
> Public Sub Encrypt()
> Dim a(4) As Integer
> Dim looper As Integer
> Dim holdstr As String
> a(1) = 25
> a(2) = 67
> a(3) = 44
> a(4) = 101
> looper = 1
> For i = 1 To Len(AdminPwd)
>  enc = Asc(Mid(AdminPwd, i, 1))
>  newchar = Chr(enc Xor a(looper))
>  holdstr = holdstr & newchar
>  looper = looper + 1
>  If looper = 5 Then looper = 1
> Next i
> End Sub
>
Author
23 Sep 2005 5:24 PM
Ralph
<nospam@meatonconsulting.com> wrote in message
Show quoteHide quote
news:1127487044.976564.239230@g14g2000cwa.googlegroups.com...
> Ok, I'm still having problems.  I have my constant declared using the
> encrypted password.  I somehow need to decrypt the password and then
> use it in another statement that needs a constant to run correctly.
> Here is all of the code:
>
> Public passwrd As String
> Public encryptedpasswd As String
> Private Const AdminUser = "refupdlocal"
> Private Const AdminPwd = "EncryptedPassw0rd"
> Public Passwd As String
> Private Const LOGON_WITH_PROFILE As Long = &H1&
> Private Const LOGON_NETCREDENTIALS_ONLY As Long = &H2&
> Private Const WAIT_TIMEOUT = 258&
> Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
>
> Private Type STARTUPINFOW
>   cb As Long
>   lpReserved As Long
>   lpDesktop As Long
>   lpTitle As Long
>   dwX As Long
>   dwY As Long
>   dwXSize As Long
>   dwYSize As Long
>   dwXCountChars As Long
>   dwYCountChars As Long
>   dwFillAttribute As Long
>   dwFlags As Long
>   wShowWindow As Integer
>   cbReserved2 As Integer
>   lpReserved2 As Long
>   hStdInput As Long
>   hStdOutput As Long
>   hStdError As Long
> End Type
>
> Private Type PROCESS_INFORMATION
>     hProcess As Long
>     hThread As Long
>     dwProcessId As Long
>     dwThreadId As Long
> End Type
>
> Private Declare Function GetCommandLine Lib "kernel32" Alias _
>     "GetCommandLineA" () As Long
> Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" ( _
>     ByVal lpString1 As String, ByVal lpString2 As Long) As Long
> Private Declare Function GetUserName Lib "advapi32.dll" Alias _
>     "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
> Private Declare Function CreateProcessWithLogonW Lib "advapi32" ( _
>     ByVal lpUsername As Long, ByVal lpDomain As Long, _
>     ByVal lpPassword As Long, ByVal dwLogonFlags As Long, _
>     ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, _
>     ByVal dwCreationFlags As Long, lpEnvironment As Any, _
>     ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFOW, _
>     lpProcessInfo As PROCESS_INFORMATION) As Long
> Private Declare Function GetComputerName Lib "kernel32" Alias _
>     "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As
> Long
> Private Declare Function FormatMessage Lib "kernel32" Alias _
>     "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, _
>     ByVal dwMessageId As Long, ByVal dwLanguageId As Long, _
>     ByVal lpBuffer As String, ByVal nSize As Long, _
>     Arguments As Long) As Long
> Private Declare Function WaitForSingleObject Lib "kernel32" ( _
>     ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
> Private Declare Function TerminateProcess Lib "kernel32" ( _
>     ByVal hProcess As Long, ByVal uExitCode As Long) As Long
>
> Private Function CommandLine() As String
>     Dim lpStr As Long, i As Long
>     Dim Buffer As String
>     Dim cmdLine As String
>
>
>     lpStr = GetCommandLine()
>     Buffer = Space$(512)
>     lstrcpy Buffer, lpStr
>     Buffer = Left$(Buffer, InStr(Buffer & vbNullChar, vbNullChar) - 1)
>     If Left$(Buffer, 1) = """" Then
>         i = InStr(2, Buffer, """")
>         cmdLine = LTrim$(Mid$(Buffer, i + 1))
>     Else
>         i = InStr(Buffer, " ")
>         cmdLine = LTrim$(Mid$(Buffer, i))
>     End If
>     CommandLine = cmdLine
> End Function
>
>
> Function UserName() As String
>     Dim lpBuffer As String
>     Dim nSize As Long
>     Dim lError As Long
>     lpBuffer = Space(255)
>     nSize = Len(lpBuffer)
>     Call GetUserName(lpBuffer, nSize)
>     UserName = Left(lpBuffer, InStr(1, lpBuffer, Chr(0)) - 1)
> End Function
>
>
> Private Function GetErrorMessage(Error As Long) As String
>     Dim Buffer As String
>     Dim lBuffer As Long
>     Buffer = String(1024, 0)
>     lBuffer = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&,
> Error, _
>         0, Buffer, 200, ByVal 0&)
>     GetErrorMessage = Left(Buffer, lBuffer)
> End Function
>
>
> Private Function ComputerName() As String
>     Dim lpBuffer As String
>     Dim nSize As Long
>     Dim lError As Long
>     lpBuffer = Space(255)
>     nSize = Len(lpBuffer)
>     Call GetComputerName(lpBuffer, nSize)
>     ComputerName = Left(lpBuffer, nSize)
> End Function
>
>
> Private Function RunAs(sUser As String, sPwd As String, _
>     sCmdLine As String, Optional Parameters As String = "", _
>     Optional Directory As String = "", _
>     Optional WindowStyle As VbAppWinStyle = vbNormalFocus, _
>     Optional Wait As Boolean = False, Optional Timeout As Long = -1, _
>     Optional Terminate As Boolean = False, _
>     Optional hProcess As Long) As Long
>     Dim SInfo As STARTUPINFOW
>     Dim PInfo As PROCESS_INFORMATION
>     Dim aUser() As String
>     Dim sDomain As String
>     Dim sUsername As String
>     Dim sDir As String
>     Dim sCmd As String
>     Dim Res As Long
>
>
>     aUser = Split(sUser, "\")
>     If UBound(aUser) = 1 Then
>         sDomain = aUser(0)
>         sUsername = aUser(1)
>     Else
>         sDomain = ComputerName
>         sUsername = sUser
>     End If
>
>
>     SInfo.dwFlags = STARTF_USESHOWWINDOW
>     SInfo.wShowWindow = WindowStyle
>
>
>     If Directory = "" Then
>         sDir = CurDir
>     Else
>         sDir = Directory
>     End If
>
>
>     If Parameters <> "" Then
>         sCmd = sCmdLine & " " & Parameters
>     Else
>         sCmd = sCmdLine
>     End If
>
>
>     Res = CreateProcessWithLogonW(StrPtr(sUsername), StrPtr(sDomain), _
>         StrPtr(sPwd), LOGON_WITH_PROFILE, 0&, StrPtr(sCmd), 0&, ByVal
> 0&, _
>         StrPtr(sDir), SInfo, PInfo)
>
>
>     If Res <> 0 Then
>         hProcess = PInfo.hProcess
>         If Wait Then
>             If Timeout > 0 Then Timeout = Timeout * 1000
>             If WaitForSingleObject(PInfo.hProcess, _
>                 Timeout) = WAIT_TIMEOUT Then
>                 RunAs = WAIT_TIMEOUT
>                 If Terminate Then
>                     If TerminateProcess(PInfo.hProcess, 0) = 0 Then
>                         RunAs = Err.LastDllError
>                     End If
>                 End If
>             End If
>         End If
>     Else
>         RunAs = Err.LastDllError
>         hProcess = 0
>     End If
> End Function
>
>
> Sub Main()
>     Dim Res As Long
>
>
>     If LCase(UserName) <> LCase(AdminUser) Then
>         Res = RunAs(AdminUser, AdminPwd, "JDSecure20.exe", _
>             CommandLine)
>         If Res <> 0 Then MsgBox GetErrorMessage(Res)
>         Exit Sub
>     End If
> End Sub
>
> Private Sub Form_Load()
> Encrypt
> Main
> Unload Me
> End Sub
>
> Public Sub Encrypt()
> Dim a(4) As Integer
> Dim looper As Integer
> Dim holdstr As String
> a(1) = 25
> a(2) = 67
> a(3) = 44
> a(4) = 101
> looper = 1
>  For i = 1 To Len(AdminPwd)
>   enc = Asc(Mid(AdminPwd, i, 1))
>   newchar = Chr(enc Xor a(looper))
>   holdstr = holdstr & newchar
>   looper = looper + 1
>   If looper = 5 Then looper = 1
>  Next i
> End Sub
>

I'm confused. Where exactly is it that you feel you need a Constant?

Second, hopefully that isn't the real code you expect to use to decrypt a
password. It will guard against the intermediate, but would be cracked by
the determined in a very short time. That may be enough security for your
purposes. I just didn't want you to think it would guard from all possible
attacks.

-ralph
Author
26 Sep 2005 6:15 PM
nospam
Apparently I did not need a constant for the password.  I figured out
how to launch it without it.  This code is going to be used internally
to launch an exe as a local admin.  It will only be used by a handful
of people, and the encryption is only so they can't see the password in
notepad.  I'm sure some of the guys I work with could crak it in
minutes :)  Thanks for the suggestions, and sorry it was a question
that could have been avoided!
Author
26 Sep 2005 6:46 PM
Ralph
<nospam@meatonconsulting.com> wrote in message
news:1127758558.484980.36150@g14g2000cwa.googlegroups.com...
> Apparently I did not need a constant for the password.  I figured out
> how to launch it without it.  This code is going to be used internally
> to launch an exe as a local admin.  It will only be used by a handful
> of people, and the encryption is only so they can't see the password in
> notepad.  I'm sure some of the guys I work with could crak it in
> minutes :)  Thanks for the suggestions, and sorry it was a question
> that could have been avoided!
>

With the example you gave, you have an simpler (and likely more secure
method) available to you. Place the executable in a folder and give the
folder 'Read & Execute' permission for a workgroup deny everything for
others. people can run it, but not "edit" it.
-ralph