Jump to content

FileCreateShortcut


Recommended Posts

I've written a setup script which installs another script that gives the user the ability to update database files from a network drive. Once the file setup is complete on the user's hard drive, it then creates a desktop shortcut. As different users may use the same computer and they all log in under their names, I've decided to create the shortcut in "C:\Documents and Settings\All Users\Desktop". Doing it this way installs the shortcut to the desktop of all users of that computer. That way, the setup is run once and all users have access to the shortcut.

This works great under W2K. My problem is with WXP-Pro. It will not create the shortcut-unless I am logged is as Administrator. I can however create the shortcut on the desktop of the logged in user but every other user will have to run the setup which is what I am trying to prevent.

I've tried the RunAsSet(), but to no avail. I know I should then be using Run() but this is for an external program and the command is in the script. Any suggestions? Here is a copy of the function :

Func Install_sc()
    
    RunAsSet("Administrator", "Domain" , "Password")
    FileCreateShortcut("C:\LkUp-SD\LkUp-SD.exe",@DesktopCommonDir & "\LkUp-SD.lnk","C:\LkUp-SD", "C:\Scripts\LkUp-SD\ParkPlace.ico") 
    RunAsSet()
    
EndFunc
Link to comment
Share on other sites

  • Developers

I've written a setup script which installs another script that gives the user the ability to update database files from a network drive.  Once the file setup is complete on the user's hard drive, it then creates a desktop shortcut.  As different users may use the same computer and they all log in under their names, I've decided to create the shortcut in "C:\Documents and Settings\All Users\Desktop".  Doing it this way installs the shortcut to the desktop of all users of that computer.  That way, the setup is run once and all users have access to the shortcut.

This works great under W2K.  My problem is with WXP-Pro.  It will not create the shortcut-unless I am logged is as Administrator.  I can however create the shortcut on the desktop of the logged in user but every other user will have to run the setup which is what I am trying to prevent.

I've tried the RunAsSet(), but to no avail.  I know I should then be using Run() but this is for an external program and the command is in the script.  Any suggestions?  Here is a copy of the function :

Func Install_sc()
    
    RunAsSet("Administrator", "Domain" , "Password")
    FileCreateShortcut("C:\LkUp-SD\LkUp-SD.exe",@DesktopCommonDir & "\LkUp-SD.lnk","C:\LkUp-SD", "C:\Scripts\LkUp-SD\ParkPlace.ico") 
    RunAsSet()
    
EndFunc

<{POST_SNAPBACK}>

RunAsSet() only changes the credentials for the Run() or RunWait() command!

If you want to change the credentials for all functions in the script you need to restart the script using the administrator account....

something like:

AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 
Break(0)
$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0     ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
   Exit
EndIf
; commands go here that require Administrator rights
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

RunAsSet() only changes the credentials for the Run() or RunWait() command!

If you want to change the credentials for all functions in the script you need to restart the script using the administrator account....

something like:

AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 
Break(0)
$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0    ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
   Exit
EndIf
; commands go here that require Administrator rights

<{POST_SNAPBACK}>

I've included your script into mine but I just keep getting the MsgBox for @error. I might not be doing it right. For one thing, I don't understand the use of $CMDLINE or $RUN. For another, I'm not sure I understand the syntax of the Run command as you've written it. Also, I've split up your script with the first six lines at the top of mine and the rest in the function Install_sc(). I'm including the full script. Hope you can help!

; ===================================================================
; SetupLkUp.exe version 1.0 compilé le 20 avril 2005
; Ce programme crée le répertoire C:\LkUp-SD et tous les sous-répertoires,
; installe LkUp-Sd.exe et fait un raccourci pour celui-ci sur le desktop,
; copie SD33.exe dans chaqur sous-répertoire et télécharge les bases de
; données pour chaque bureau
; ===================================================================
AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 
Break(0)
$USERNAME = "Jusrentinst"
$PASSWORD = "Justice*99"
$RUN = 0    ; run indicator 

#include <GUIConstants.au3>
$choix_dir = StringSplit("BATH,EDM,FTON,MON,SJ",  ",")
$fichiers = StringSplit("control.dbf ,landlord.dbf ,byllnum.ntx ,byllname.ntx ,tenant.dbf ,bytnum.ntx ,xref.dbf ,byxrname.ntx ,byxrllna.ntx ,journal.dbf ,byjllnum.ntx ,byjdate.ntx ,dtenant.dbf ,dbytnum.ntx ,dxref.dbf ,dbyxrnam.ntx ,djournal.dbf ,dbyjllnu.ntx ,dbyjdate.ntx ", ",")
$choix_bur = StringSplit("Bathurst ,Edmundston ,Fredericton ,Moncton ,Saint John ", ",")

; ========================================
; Vérifier si le lecteur L: est accessible
; ========================================
If DriveStatus("L:\") = "INVALID" Then
    MsgBox(16,"Mapped drive error - Erreur d'unité mappé","The drive L:\ (\\jusfp01\jusrentdbf$) has not been mapped." & @CRLF & "              Please call Help Desk for assistance." & @CRLF & "" & @CRLF & "  L'unité L:\ (\\jusfp01\jusrentdbf$) n'a pas été mappé." & @CRLF & "Téléphonner le Service d'aide technique pour assistance.")
EndIf

; ======================================
; Vérifier si Setup-LkUp.exe fut exécuté
; ======================================
$Shortcut = @DesktopCommonDir & "\LkUp-SD.lnk"
$Shortcut_Exist = FileExists($Shortcut)
$Dir = "C:\LkUp-SD"
$Dir_Exist = FileExists($Dir)

Select
    Case $Shortcut_Exist=1 And $Dir_Exist=1
        $iMsgBoxAnswer = MsgBox(52,"Already installed - Déjà installer","The program is already setup.  Do you wish to delete the program and install again?" & @CRLF & "" & @CRLF & "Le programme est déjà installé.  Désirez-vous le supprimer et l'installer à nouveau?")
        If $iMsgBoxAnswer = 6 Then;Yes
            DirRemove($Dir,1)
            FileDelete($Shortcut)
            Install_db()
            Install_sc()
        Else
            Exit
        EndIf
    Case $Shortcut_Exist=1 And $Dir_Exist=0
        FileDelete($Shortcut)
        Install_db()
        Install_sc()
    Case $Shortcut_Exist=0 And $Dir_Exist=1
        MsgBox(48,"Missing shortcut - Raccourci manquant","  The missing shortcut will be created.  If this does not resolve the issue, " & @CRLF & "               run this setup program again and chose to install again." & @CRLF & "" & @CRLF & "            Le raccourci sera créé.  Si ceci ne règle pas le problème," & @CRLF & "veuillez exécuter le programme d'installation et choisissez d'installer encore.")
        Install_sc()
    Case Else
        Install_db()
        Install_sc()
EndSelect

; =======
; Terminé
; =======
MsgBox(0,"Setup completed - Installation complétée","The shortcut LkUp-SD has been created on your desktop." & @CRLF & "              Use this to launch the rent program." & @CRLF & "" & @CRLF & "  Le raccourci pour LkUp-SD à été créé sur votre bureau. " & @CRLF & "  Utilisez ce dernier pour exécuter le programme de rent.")

; =========
; Functions
; =========

Func Install_db()
    
    DirCreate("C:\LkUp-SD\Bath")
    DirCreate("C:\LkUp-Sd\Edm")
    DirCreate("C:\LkUp-SD\Fton")
    DirCreate("C:\LkUp-Sd\Mon")
    DirCreate("C:\LkUp-SD\SJ")
    FileInstall("C:\Scripts\LkUp-SD\LkUp-SD.exe" , $Dir & "\")
    For $i = 1 to 5; faire un bureau à la fois
        FileInstall("C:\Scripts\LkUp-SD\SD33.exe", $Dir & "\" & $choix_dir[$i] & "\")
        GUICreate($choix_bur[$i],260,40)
        $progress_bar = GUICtrlCreateProgress(30,10,200,20)
        GUISetState()
        For $j = 1 to 19; copier la base des données
            FileCopy("L:\" & $choix_dir[$i] & "\RENT\" & $fichiers[$j], $Dir & "\" & $choix_dir[$i] & "\",1)
            GUICtrlSetData($progress_bar, ($j*100/19))
        Next
        GUIDelete()
    Next
    
    
EndFunc

Func Install_sc()
    
    If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
    If $RUN = 0 Then
        RunAsSet($USERNAME, @LogonDomain, $PASSWORD)
        Run('"' & @ScriptFullPath & '" " 1"') 
    If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
        Exit
    EndIf
    FileCreateShortcut("C:\LkUp-SD\LkUp-SD.exe",@DesktopCommonDir & "\LkUp-SD.lnk","C:\LkUp-SD", "C:\Scripts\LkUp-SD\ParkPlace.ico") 
        
EndFunc
Link to comment
Share on other sites

  • Developers

By the way, I've also tried including all of your script at the beginning of mine but still getting the error on starting under admin mode.  I've also tried changing the computer name to the domain name.  Same results.

<{POST_SNAPBACK}>

It needs to be at the top of the script and you have to compile it and run the compiled version or else it cannot restart itself....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It needs to be at the top of the script and you have to compile it and run the compiled version or else it cannot restart itself....

<{POST_SNAPBACK}>

Moved everything to the top of the script, compiled and ran. Same error. I know I'm missing something but I can't figure it out. Here is the new beginnig of the script which is what you gave me. What would give a value to $CMDLINE?

AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 
Break(0)
$USERNAME = "Jusrentinst"
$PASSWORD = "Justice*99"
$RUN = 0    ; run indicator 

If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
    RunAsSet($USERNAME, @ComputerName, $PASSWORD)
    Run('"' & @ScriptFullPath & '" " 1"') 
If @error Then MsgBox(4096+32,"Error", @error & " - Error starting under admin mode")
    Exit
EndIf

#include <GUIConstants.au3>

Also changed the Install_sc() funtion to the following:

Func Install_sc()
    
    FileCreateShortcut("C:\LkUp-SD\LkUp-SD.exe",@DesktopCommonDir & "\LkUp-SD.lnk","C:\LkUp-SD", "C:\Scripts\LkUp-SD\ParkPlace.ico") 
        
EndFunc
Link to comment
Share on other sites

  • Developers

Moved everything to the top of the script, compiled and ran.  Same error.  I know I'm missing something but I can't figure it out.  Here is the new beginnig of the script which is what you gave me.  What would give a value to $CMDLINE?

<{POST_SNAPBACK}>

Looks ok to me...

You are getting the error on the Run command to restart itself in Admin mode right ?

Sorry for asking but you are sure about the Local account username & password ?

I am using this trick on several scripts without any issue...

EDIT: and you are running the EXE version ..right ?

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Looks ok to me...

You are getting the error on the Run command to restart itself in Admin mode right ?

Sorry for asking but you are sure about the Local account username & password ?

I am using this trick on several scripts without any issue...

EDIT: and you are running the EXE version ..right ?

<{POST_SNAPBACK}>

Yes, I am getting the Admin mode error. I checked the Username and password by login on and it works with full priviledges. I am also running the compiles version (*.exe).

Again, how does the $CMDLINE variable get a value?

Link to comment
Share on other sites

  • Developers

And the account you use is a PC account, not a Domain account .. right ?

Again, how does the $CMDLINE variable get a value?

<{POST_SNAPBACK}>

That is an build in Variable ...

Its in the helpfile but not always easy to find but you can do it via Search..

Command Line Parameters

The special array $CmdLine is initialized with the command line parameters passed in to your AutoIt script.  Note the scriptname is not classed as a parameter; get this information with @ScriptName instead.  A parameter that contains spaces must be surrounded by "double quotes".  Compiled scripts accept command line parameters in the same way.

$CmdLine[0] is number of parameters

$CmdLine[1] is param 1 (after the script name)

$CmdLine[2] is param 2 etc

$CmdLine[$CmdLine[0]] is one way to get the last parameter...

So if your script is run like this:

    AutoIt3.exe myscript.au3 param1 "this is another param"

$CmdLine[0] equals... 2

$CmdLine[1] equals... param1

$CmdLine[2] equals... this is another param

@ScriptName equals... myscript.au3

In addition to $CmdLine there is a variable called $CmdLineRaw that contains the entire command line unsplit, so for the above example:

$CmdLineRaw equals... myscript.au3 param1 "this is another param"

EDIT: Just ran your script portion on an WinXP PRO (ofcource changed the name/psw of the local admin account) and it ran fine..... Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

And the account you use is a PC account, not a Domain account ..  right ?

.

.

.

EDIT: Just ran your script portion on an WinXP PRO (ofcource changed the name/psw of the local admin account) and it ran fine.....

<{POST_SNAPBACK}>

I checked with IT about PC versus Domain. The answer was as clear as mud. They said it was both???

I borrowed the idea from your script and added a MsgBox

If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
    RunAsSet($USERNAME, @ComputerName, $PASSWORD)
MsgBox(4096+32,"Error", @error & " - RunAsSet")
    Run('"' & @ScriptFullPath & '" " 1"') 
If @error Then MsgBox(4096+32,"Error", @error & " - Error starting under admin mode")
    Exit
EndIf

RunAsSet always returns 0. I've tried it with @ComputerName, @LogonDomain and @LogonDNSDomain. Always the same result. Documentation for RunAsSet says :"The "Secondary Logon service" or "RunAs service" must not be disabled if you want this function to work." I don't know what they are refering to. Network administration is not my thing. Any ideas? P.S. I'm on W2K today.

Link to comment
Share on other sites

  • Developers

I checked with IT about PC versus Domain.  The answer was as clear as mud.  They said it was both???

<{POST_SNAPBACK}>

To my knowledge they can only be really the same when its a DC (Domain controller) ... so you could try to replace the @Computername with "YOUR DOmain Name".

RunAsSet always returns 0.  I've tried it with @ComputerName, @LogonDomain and @LogonDNSDomain.  Always the same result.  Documentation for RunAsSet says :"The "Secondary Logon service" or "RunAs service" must not be disabled if you want this function to work."  I don't know what they are refering to.  Network administration is not my thing.  Any ideas?  P.S. I'm on W2K today.

<{POST_SNAPBACK}>

Check under Adminstrative tools/Services for these 2 services and see if it says they are started..... Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

To my knowledge they can only be really the same when its a DC (Domain controller) ...  so you could try to replace the @Computername with "YOUR DOmain Name".

Check under Adminstrative tools/Services for these 2 services and see if it says they are started.....

<{POST_SNAPBACK}>

Thanks for your support. I'm on vacation for a week so I don't have access to those computers to follow up. But I'll be back. Just wanted to let you know I appreciate your support and patience.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...