|
-
Apr 29th, 2006, 10:42 AM
#1
Thread Starter
Lively Member
[RESOLVED] Three questions
Okay just three simple (well not to me) questions that I need help with.
How can I move a file form a Floopy Disk to a Folder?
Can I use VB to set one of my own .exe files as a start up program? If so how?
Can I make folders useing VB? If so how?
Cheers,
~ichar
-
Apr 29th, 2006, 10:49 AM
#2
Re: Three questions
VB Code:
Name "A:\myfile.txt" As "C:\myfile.txt"
Start-up: http://www.vbforums.com/showthread.php?t=397508
you have to create sub-folders first using MkDir, or you could use API: MakeSureDirectoryPathExists which will create all folders & subfolders in one go.
-
Apr 29th, 2006, 11:03 AM
#3
Addicted Member
Re: Three questions
Question 1:
By using reference Microsoft Scripting Runtime
Private oFS As New FileSystemObject
FileSystemObject has functions inside for purposes like this, and one of them happens to be called MoveFile
oFS.MoveFile(Source As String, Destination As String)
Source$ = Your floppy path
Destination$ = The new path you want to send the source to
-----------------------------------------------------
Question 2:
Yes you can , but you must create a key under:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
named after the executables name with a value.
Constants , and Functions required:
Code:
Public Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Const READ_CONTROL = &H20000
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Public Const SYNCHRONIZE = &H100000
Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Public Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Const ERROR_SUCCESS = 0&
Public Const HKEY_CURRENT_USER = &H80000001
Public Const REG_SZ = 1
Code:
Public Sub SetRunAtStartup(ByVal app_name As String, ByVal app_path As String, Optional ByVal run_at_startup As Boolean = True)
Dim hKey As Long
Dim key_value As String
Dim status As Long
On Error GoTo SetStartupError
' Open the key, creating it if it doesn't exist.
If RegCreateKeyEx(HKEY_CURRENT_USER, _
"Software\Microsoft\Windows\CurrentVersion\Run", _
ByVal 0&, ByVal 0&, ByVal 0&, _
KEY_WRITE, ByVal 0&, hKey, _
ByVal 0&) <> ERROR_SUCCESS _
Then
MsgBox "Error " & Err.Number & " opening key" & _
vbCrLf & Err.Description
Exit Sub
End If
' See if we should run at startup.
If run_at_startup Then
' Create the key.
key_value = app_path & "\" & app_name & ".exe" & vbNullChar
status = RegSetValueEx(hKey, App.EXEName, 0, REG_SZ, _
ByVal key_value, Len(key_value))
If status <> ERROR_SUCCESS Then
MsgBox "Error " & Err.Number & " setting key" & _
vbCrLf & Err.Description
End If
Else
' Delete the value.
RegDeleteValue hKey, app_name
End If
' Close the key.
RegCloseKey hKey
Exit Sub
SetStartupError:
MsgBox Err.Number & " " & Err.Description
Exit Sub
End Sub
'Will Return True if the program is set to run at startup.
Public Function WillRunAtStartup(ByVal app_name As String) As Boolean
Dim hKey As Long
Dim value_type As Long
' See if the key exists.
If RegOpenKeyEx(HKEY_CURRENT_USER, _
"Software\Microsoft\Windows\CurrentVersion\Run", _
0, KEY_READ, hKey) = ERROR_SUCCESS _
Then
' Look for the subkey named after the application.
WillRunAtStartup = _
(RegQueryValueEx(hKey, app_name, _
ByVal 0&, value_type, ByVal 0&, ByVal 0&) = _
ERROR_SUCCESS)
' Close the registry key handle.
RegCloseKey hKey
Else
' Can't find the key.
WillRunAtStartup = False
End If
End Function
I usually create a CheckBox and ask the user if he/she wants to set it to run up at startup.
SetRunAtStartup(ByVal app_name As String, ByVal app_path As String, Optional ByVal run_at_startup As Boolean = True)
Ex:
SetRunAtStartUp App.EXEName, App.Path, True
if your using a checkbox then:
SetRunAtStartup App.EXEName, App.Path, (chk.Value = vbChecked)
and finally to check if your App is running at StartUp use WillRunAtStartUp.
If WillRunAtStartup(App.EXEName) Then 'My program is set to run at startup now check my checkbox telling the user it is running at startup.
chk.Value = vbChecked
Else 'My program isnt set to run at startup now uncheck it telling the user it isnt running at startup.
chk.Value = vbUnchecked
End If
Question 3:
Yes there is a way to create folders by using FileSystem or FileSystemObject (which requires Microsoft Scripting Runtime)
FileSystem way:
FileSystem.MkDir(Path As String)
or
MkDir(Path As String)
FileSystemObject way:
Private oFS As New FileSystemObject
FileSystemObject has functions inside for purposes like this, and one of them happens to be called CreateFolder
oFS.CreateFolder(Path As String)
-
Apr 29th, 2006, 11:04 AM
#4
Thread Starter
Lively Member
Re: Three questions
Thanks, a few more questions.
How can I remove the Close, Min/Max and Restore Buttons from a form?
How can I remove the blue bar at the top of a form?
And how can I make aform the uppermost form?
I.E. effectivly Lock my workstation.
-
Apr 29th, 2006, 11:10 AM
#5
Addicted Member
Re: Three questions
Question 1:
Look at your Properties window when you click on your form, there should be something called MinButton and MaxButton , set either True/False.
Question 2:
You'll have to look in your Properties window under Borderstyle and set it to none.
Question 3:
Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Dim ans As Long 'To get the response back
ans& = SetWindowPos(hWnd, -1, 0, 0, 0, 0, 1 Or 2)
this will make your form the uppermost form.
-
Apr 29th, 2006, 11:12 AM
#6
Re: Three questions
to remove min/max & close set the ControlBox property = False
-
Apr 29th, 2006, 11:22 AM
#7
Lively Member
Re: Three questions
to remove the minimize, maximize and close button and the title bar from ur form, change the BorderStyle to 0-none.
to make ur form always on top:
VB Code:
'Declaration
Public Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2
Public Const OOMPS = SWP_NOSIZE Or SWP_NOMOVE
_________________________________________________________________
Private Sub Form_Load()
'This is the code to enable the always-on-top action
Call SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, OOMPS)
End Sub
'This is to disable it, put this code in a desired control
Call SetWindowPos(Form1.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, OOMPS)
Hope that will help!
I'm Still learning!
satisfied/not satisfied, PLEASE TAKE SOME TIME TO rate me accordingly.
Ur opinions helps me to be better!
Appreciation Triggers Another Good Deeds.
-
Apr 29th, 2006, 11:49 AM
#8
Thread Starter
Lively Member
Re: Three questions
Cheers guys. Your all great
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|