[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

AutoStart And Run At Boot Only

BeeJ

12/12/2011 12:01:00 AM

My little backup app needs to start and run if windows is booted.

I am trying the following code to create a startup shortcut in the auto
start folder.

But I need to let my app know that it is being auto started perhaps
with a command line argument.

Not sure how to do this such that if I double click the app it starts
but does not run but if auto started it starts and runs.

NOTE TO SELF: FIX DECLARATION LOCATION
Public oShell As Shell32.Shell
Public sPath As String
Public sStartup As String
Public sShellPath As String

Private Sub Form_Load()

' CODE IS HERE JUST FOR DEVELOPMENT
Set oShell = New Shell32.Shell
AutoStartShortcutMake

End Sub

Public Sub AutoStartShortcutMake()

With Shell.NameSpace(ssfPERSONAL).Self
sPath = App.Path & "\" & App.EXEName & ".exe"
End With

' REVISE TO CHECK FOR FOLDER AND AVOID ERROR CODE
On Error Resume Next
MkDir sPath
Debug.Print Err.Description
On Error GoTo 0

With Shell.NameSpace(ssfSTARTUP).Self
sStartup = .Path & "\" & App.EXEName & ".lnk"
End With

With Shell.NameSpace(ssfSYSTEM).Self
sShellPath = .Path & "\Shell32.dll"
End With

ShortcutCreate sPath, _
sStartup, _
"Start " & App.EXEName, _
sShellPath, _
24

End Sub 'AutoStartShortcutMake

Private Sub ShortcutCreate( _
ByVal sItemPath As String, _
ByVal sLinkPath As String, _
ByVal sDescription As String, _
ByVal sIconPath As String, _
ByVal lIconNumber As Long)

Dim lFNbr As Long

lFNbr = FreeFile(0)
Open sLinkPath For Output As #lFNbr
Close #lFNbr

With Shell.NameSpace(ssfDESKTOP).ParseName(LinkPath).GetLink
.Path = sItemPath
.Description = sDescription
.SetIconLocation sIconPath, lIconNumber
.Save
End With

End Sub 'ShortcutCreate


7 Answers

BeeJ

12/12/2011 12:49:00 AM

0

I tried modifying the line every way I can think of.

Const csDQ As String = """"
Const csSp1 As String = " "

.Path = csDQ & sItemPath & csDQ & csSp1 & csDQ & "/CommandLine" & csDQ

And it always changes the / to a \ in the shortcut (all else goes
through properly) and the shortcut does not work.
if I manually edit the sortcut to / it works.

I tried using \ as an escape as in "\/CommandLine", no go.
I tried using single quotes, no go.
Suggestions please.


Dee Earley

12/12/2011 12:46:00 PM

0

On 12/12/2011 00:01, BeeJ wrote:
> My little backup app needs to start and run if windows is booted.
>
> I am trying the following code to create a startup shortcut in the auto
> start folder.
>
> But I need to let my app know that it is being auto started perhaps with
> a command line argument.
>
> Not sure how to do this such that if I double click the app it starts
> but does not run but if auto started it starts and runs.

I can't help with using the Shell32 object library, but I use this:

Dim Shell As Object 'WshShell
Dim NewShortcut As Object 'WshShortcut

Set Shell = CreateObject("wscript.shell.1")
Set NewShortcut = Shell.CreateShortcut(Destination & Name & ".lnk")
NewShortcut.TargetPath = Target
NewShortcut.Arguments = Parameters
If Icon <> "" Then NewShortcut.IconLocation = Icon
NewShortcut.Save

--
Deanna Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

DaveO

12/12/2011 2:27:00 PM

0

I hope this is just for personal use.



I HATE programs that insist on running on boot up. Windows boots to the
desktop quite quickly and then is unusable sometimes for minutes as a host
of programs each knowing they are more important than any other program hog
the resources phoning home or checking this or that which I invariably don't
want done but these programs seldom provide the option to prevent or delay
the run at boot up. After all each one is the greatest program ever and
nobody would ever need to stop it doing everything. (Yes Macromedia and
Adobe, I'm referring to you!)



What I thinkWindows needs is some kind of start up scheduler which will only
allow boot up processes to run sequentially rather than simultaneously.



Regards

DaveO


"BeeJ" <nospam@spamnot.com> wrote in message
news:jc3g84$7ge$1@speranza.aioe.org...
> My little backup app needs to start and run if windows is booted.
>
> I am trying the following code to create a startup shortcut in the auto
> start folder.
>
> But I need to let my app know that it is being auto started perhaps with a
> command line argument.
>
> Not sure how to do this such that if I double click the app it starts but
> does not run but if auto started it starts and runs.
>
> NOTE TO SELF: FIX DECLARATION LOCATION
> Public oShell As Shell32.Shell
> Public sPath As String
> Public sStartup As String
> Public sShellPath As String
>
> Private Sub Form_Load()
>
> ' CODE IS HERE JUST FOR DEVELOPMENT
> Set oShell = New Shell32.Shell
> AutoStartShortcutMake
>
> End Sub
>
> Public Sub AutoStartShortcutMake()
>
> With Shell.NameSpace(ssfPERSONAL).Self
> sPath = App.Path & "\" & App.EXEName & ".exe"
> End With
>
> ' REVISE TO CHECK FOR FOLDER AND AVOID ERROR CODE
> On Error Resume Next
> MkDir sPath
> Debug.Print Err.Description
> On Error GoTo 0
>
> With Shell.NameSpace(ssfSTARTUP).Self
> sStartup = .Path & "\" & App.EXEName & ".lnk"
> End With
>
> With Shell.NameSpace(ssfSYSTEM).Self
> sShellPath = .Path & "\Shell32.dll"
> End With
>
> ShortcutCreate sPath, _
> sStartup, _
> "Start " & App.EXEName, _
> sShellPath, _
> 24
>
> End Sub 'AutoStartShortcutMake
>
> Private Sub ShortcutCreate( _
> ByVal sItemPath As String, _
> ByVal sLinkPath As String, _
> ByVal sDescription As String, _
> ByVal sIconPath As String, _
> ByVal lIconNumber As Long)
>
> Dim lFNbr As Long
>
> lFNbr = FreeFile(0)
> Open sLinkPath For Output As #lFNbr
> Close #lFNbr
>
> With Shell.NameSpace(ssfDESKTOP).ParseName(LinkPath).GetLink
> .Path = sItemPath
> .Description = sDescription
> .SetIconLocation sIconPath, lIconNumber
> .Save
> End With
>
> End Sub 'ShortcutCreate
>
>


James Tyler

12/12/2011 3:51:00 PM

0

You can schedule a task to un only at bootup. Too easy ??


Dee Earley

12/12/2011 4:08:00 PM

0

On 12/12/2011 00:01, BeeJ wrote:
> My little backup app needs to start and run if windows is booted.

Also note that Windows starting is NOT the same as a user logging in
which is what triggers the Startup group.

If you want something to be running from Windows startup, you need to
use a service, and if the user needs to interact with it, a small front
end process started when the user logs in that talks to the service.

--
Deanna Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

BeeJ

12/14/2011 11:18:00 PM

0

Used your code seed Deanna. Thanks!
I can now set, kill and read back the shortcut in any path I want.
BTW for those who insist on believing I am devious, I spent 45 years
working for a company that drives ethics into you more often than I
care to recollect. Anyway, I always offer options to my users (mostly
me) to enable/disable features.


Karl E. Peterson

1/10/2012 11:16:00 PM

0

BeeJ explained on 12/11/2011 :
> My little backup app needs to start and run if windows is booted.
>
> I am trying the following code to create a startup shortcut in the auto start
> folder.

Sounds problematic. Here's code to get into the registry's Run key(s):

http://vb.mvps.org/sample...

--
..NET: It's About Trust!
http://vfre...