CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1

    Question security question???

    the software im writeing i want it to install from a cd and be able to make the program run only while the cd is in the drive make it read a file or something from cd when it saves a record ,it can be a anything.dat file i know peoples cd's some are different letter mine is G:\ some are D:\ when i install from cd is there a way i can save the drive letter so i can put a file on the cd my program read every time l know this is not a fool proof soulution for protection but i would really like to know how to do this thank you for any help or insights

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: security question???

    You can use the App.Path variable to return the drive and folder that the app is being run from. You can't save files there on the CD from your app, but you can read from there.
    Code:
    MsgBox "App is in: " & App.Path & "\"
    Don't forget to add the "\" on the end. You have to check to see if it's there.
    There are also problems if the app is installed in the root folder of a drive.

    Always use a sub folder, and you'll be safe. If not, check the len() to see if it's greater than 3 (D:\)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Dec 2001
    Posts
    6,332

    Re: security question???

    To make a program only run while the CD is in the drive, I might try using the disc serial number. If you copy the serial number of the disc during installation, then every time the program starts, compare the stored number with the one in the drive (if any). The thing is, the install file could be copied to another CD, so this doesn't offer any copy protection. To do that is much more difficult. A common technique is to require user registration before issuing a unique "unlock code" to allow the program to install/run only on that system. The vendor must issue a code to each user, which is based on a number that the program generates from unique system identifiers. The user must supply the number to the vendor, which is validated before a key is issued. Many low cost programs do not use this technique due to the cost involved.

    It seems software developers must expect a certain amount of piracy to take place, and price the product accordingly.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  4. #4

    Question Re: security question???

    ok thats a good idea what i came up with today is i want to program to run and install to the C:\ drive but the setup will come on a USB Jump Drive how can i make it find the usb jump drive on my computer is the H: drive but on another computer i wont know what drive it will be how can i make the program know like saving the drive letter of the jump drive when it installs from the jump drive any help will be apreated

  5. #5

    Question Re: security question???

    ok think i found a way to do this just need some help with the open input line this is the code

    Code:
    Const DRIVE_REMOVABLE = 2
    Const DRIVE_FIXED = 3
    Const DRIVE_REMOTE = 4
    Const DRIVE_CDROM = 5
    Const DRIVE_RAMDISK = 6
    
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

    Code:
    Private Sub Form_Load()
    Timer1.Enabled = True
    Command19.BackColor = &H8000&
     Dim i As Long, a As String, k As Long
        For i = 0 To 25
            a = Chr$(i + 65) & ":\"
            k = GetDriveType(a)
            Select Case k
                'Case DRIVE_REMOVABLE: Text1.Text
                Case DRIVE_REMOVABLE: List1.AddItem Left$(a, 1) & " is a removable drive"
                'Case DRIVE_REMOVABLE: List1.AddItem Left$(a, 1) & " is a removable drive"
                'Case DRIVE_FIXED: List1.AddItem Left$(a, 1) & " is a hard/non-removable drive"
                'Case DRIVE_REMOTE: List1.AddItem Left$(a, 1) & " is a remote/network drive"
                'Case DRIVE_CDROM: List1.AddItem Left$(a, 1) & " is a CD-ROM drive"
                'Case DRIVE_RAMDISK: List1.AddItem Left$(a, 1) & " is a RAM drive"
            End Select
        Next
    
    Recordlen = Len(person)
    Filenum = FreeFile
    Open DRIVE_REMOVABLE + a & "VSO\DATA\bonds.dat" For Random As Filenum Len = Recordlen
    End Sub
    this is my problem line

    Code:
    Open DRIVE_REMOVABLE + a & "VSO\DATA\bonds.dat" For Random As Filenum Len = Recordlen

    the folder is on the jump drive is
    \VSO\DATA\bonds.dat
    the drive removable shows the correct drive but get a error when i run it im sure i have the problem line wrong

    thanks for any help

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: security question???

    Looks like you could allow more than one jump drive. If not, just use an Exit For to jump out of the loop. The problem is that your constant isn't a string.
    Create a string (I called it dr for drive) and set it in your case statement.

    Code:
    Case DRIVE_REMOVABLE
       List1.AddItem Left$(a, 1) & " is a removable drive"
       dr = a 
    Case ...
    and then

    Code:
    Open dr & "VSO\DATA\bonds.dat" For Random As Filenum Len = Recordlen
    This will pass the correct string in dr
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7

    Talking Re: security question???

    i am so happy that worked it read the file from the jumpdrive perfectly and wont work if its out thank you so muc i get the error when its out

    Code:
    run time error '76':
    path not found
    is there a way to make it say please inset your usb drive or something like that im not good with error code

    thank you so much i would have never got this program going without the master of codeguru you guys rule

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: security question???

    Sure. Add an error trap.
    Code:
    On Error Goto DriveError:
      Open dr & "VSO\DATA\bonds.dat" For Random As Filenum Len = Recordlen
    ' 
    '
    '
      Close Filenum
      Exit Sub
    DriveError:
      Msgbox "Please insert the jump drive and try again!"
      On Error Goto 0
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9

    Thumbs up Re: security question???

    ok tried that this is my code thats working not sure how to add that in

    Code:
    Private Sub Form_Load()
    Close
    Timer1.Enabled = True
    Command19.BackColor = &H8000&
    0
     Dim i As Long, a As String, k As Long
        For i = 0 To 25
            a = Chr$(i + 65) & ":\"
            k = GetDriveType(a)
            Select Case k
                Case DRIVE_REMOVABLE: List1.AddItem Left$(a, 1) & " is a removable drive"
                dr = a
            End Select
        Next
    Recordlen = Len(person)
    Filenum = FreeFile
    Open dr & "VSO\DATA\bonds.dat" For Random As Filenum Len = Recordlen
    End Sub
    thanks again you just saved me so many headaches

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: security question???

    Just add the ON ERROR line before you attempt to open the file, or actually you can put it in the sub anywhere.

    Right above your End Sub, add the lines starting with Exit Sub.

    If there is no errors, the sub will exit without hitting the error trap, but if there is an error, the code will jump past the Exit Sub, and show the MsgBox. Then the Sub will exit. I assume that you click a button to open the file?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11

    Re: security question???

    the file opens when the program runs that file is only for to see if the drive is plugged in this worked perfect thanks so much again i cant say it enough i also hope this with others that want to add some added security ,i know this is not fool proof but i like it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured