Jump to content

FileCreateShortcut not working


Recommended Posts

Hello I had to make two separate scripts because the #RequireAdmin does not work with FileCreateShortcut and FileCopy. I am unsure what the problem is and it is very inconvenient for me since I am trying to create a GUI and don't want two separate scripts.

Link to comment
Share on other sites

  • Developers

You're not really being very clear with this problem definition....  so please elaborate/show scripts/whatever is needed to explain the issue you have. :)  

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

Might be good if you posted some code to show us what you are trying to do. Otherwise, we can only guess. Also, "not working" isn't a great description of what is occurring. Did you receive an error message? Did you check the value of @error? Etc.

My WAG is that you are trying to create a shortcut in the local user's directory, but can't because you are using #RequireAdmin. Might help if you explained why you are running with #RequireAdmin.

Link to comment
Share on other sites

Sorry for the confusion, here is the code. The issue is when I use #RequireAdmin the script runs and doesn't place any of the icons on the desktop. Btw I am also logged in as a regular user and then putting in admin credentials when it requires me to. I am also using the #RequireAdmin because regular users can't install applications and that is part of the other half of the script.

;Shortcut Creations

FileCreateShortcut("C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE", @DesktopDir & "\Excel.lnk")

FileCreateShortcut("C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE", @DesktopDir & "\Outlook.lnk")

FileCreateShortcut("C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE", @DesktopDir & "\Word.lnk")

;RDP Shortcut New Server
FileCopy("\\computer\Shortcuts\Remote Desktop.rdp", @DesktopDir , 0)

;RDP Shortcut Old Server
FileCopy("\\computer\Shortcuts\Remote Desktop(Old).rdp", @DesktopDir , 0)

;URL Link Shortcuts
FileCopy("\\computer\avidxchange.ico",@LocalAppDataDir,0)
FileCopy("\\computer\condocerts.ico",@LocalAppDataDir,0)
FileCopy("\\computer\TOPS ONE.ico",@LocalAppDataDir,0)

FileCreateShortcut("https://payableslockbox.com/Login.aspx", @DesktopDir & "\AvidXChange.lnk","","","", @LocalAppDataDir & "\avidxchange.ico")
FileCreateShortcut("https://condocerts.com/resaleManagement/index.cfm?&CFID=5306583&CFTOKEN=1b2e3b00b7695aeb-0D45B142-5056-B80F-3A39D89DFE7A99F0&jsessionid=876DA4C2D47C1D95CC20F42C10A04509.cfusion&rsi=567CC6CE272555CDA934FE5AEFCA5124", @DesktopDir & "\CondoCerts.lnk","","","", @LocalAppDataDir & "\condocerts.ico")
FileCreateShortcut("https://one.topssoft.com/", @DesktopDir & "\TOPS ONE.lnk","","","", @LocalAppDataDir & "\TOPS ONE.ico")

;Teams Desktop Icon Delete
FileDelete(@DesktopDir & "\Microsoft Teams.lnk")

 

Link to comment
Share on other sites

Check the value of @DesktopDir to make sure it's pointing to the desired directory (use a MsgBox because ConsoleWrite won't work with #RequireAdmin). Also check the value of @error following the call to FileCreateShortcut.

FWIW, this ran for me and gave the expected results --

#RequireAdmin

MsgBox(0, '@DesktopDir', @DesktopDir)
FileCreateShortcut("C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE", @DesktopDir & "\Excel.lnk")
MsgBox(0, "@error", @error)

 

Edited by Danp2
Strike out my incorrect statement
Link to comment
Share on other sites

Link to comment
Share on other sites

20 minutes ago, Gberrocal said:

So after running it, it looks like the DesktopDir is changed to my admin account desktop instead on the user I am logged in as, is their a way around this?

One way : run a first script that read user desktop and run the main script passing the user desktop as command line parameter.

Link to comment
Share on other sites

I cannot see at all why you think you need #RequireAdmin

At a glance I see only writes to @LocalAppDataDir and @DesktopDir. To both folders the currently loggedon user *HAS* write access.

 

These filecopies won't work, as no share name is specified:

FileCopy("\\computer\avidxchange.ico",@LocalAppDataDir,0)

 

This has to be something like this, and for filecopies I love to use "CreatePath"  in case someone has deleted the expected directory, and "overwrite" to replace an already existing file with the currently wanted version (8+1)

FileCopy("\\computer\share\path\path\avidxchange.ico",@LocalAppDataDir,8+1)

Rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

On 6/24/2020 at 5:26 PM, Danp2 said:

What about using @DesktopCommonDir instead of @DesktopDir?

Yeah I may just use this for now, I didn't really want to put icons on the public desktop but instead their personal account but I can't play with this script for too long.

Link to comment
Share on other sites

On 6/26/2020 at 8:15 AM, rudi said:

I cannot see at all why you think you need #RequireAdmin

At a glance I see only writes to @LocalAppDataDir and @DesktopDir. To both folders the currently loggedon user *HAS* write access.

 

These filecopies won't work, as no share name is specified:

FileCopy("\\computer\avidxchange.ico",@LocalAppDataDir,0)

 

This has to be something like this, and for filecopies I love to use "CreatePath"  in case someone has deleted the expected directory, and "overwrite" to replace an already existing file with the currently wanted version (8+1)

FileCopy("\\computer\share\path\path\avidxchange.ico",@LocalAppDataDir,8+1)

Rudi

I do have the share drive name correctly inputted on my script. I also need admin access because regular users can not install applications and the other part of the script does that. 

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...