Solved

The item this shortcut refers to has been changed or moved

Posted on 2009-03-30
13
2,370 Views
Last Modified: 2013-11-27
I use the code below to create a desktop shortcut using WScript.shell. It creates the desktop icon successfully. When I double click the icon to log in to the database, I ge the message that it can;t find the mdw named in the TargetPath. This TargetPath string is exactly the same as the target path of the icon I created manually/ Why does it say it can;t find the mdw when it is in fact in the named folder? Am I doing something wrong with the properties when I create the icon?
Dim myWSH as object

Dim strAccessPath As String

Dim strShortcutTarget As String
 

Set myWSH = CreateObject("WScript.Shell")

strAccessPath = myWSH.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Access\InstallRoot\Path")

strAccessPath = strAccessPath & "MSACCESS.EXE"

strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34) & " " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _

 & " /wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)
 

Set WSHShortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")

With WSHShortcut

    .TargetPath = strShortcutTarget

    .IconLocation = strAccessPath & ",1"

    .WorkingDirectory = "C:\"

    .Save

End With

Set myWSH = Nothing

Set WSHShortcut = Nothing

Open in new window

0
Comment
Question by:paulmcneil
  • 7
  • 5
13 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24019457
Im thinking  this might need to be broken down

strShortcutTarget should be strAccessPath

And I think there is another property you can set called Arguments

so

.Arguments = "C:\BWPhysicianOrg\BWPOBillingCoding.mdb /wrkgrp C:\BWPhysicianOrg\BWPOBillingCoding.mdw"


0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24019722
I'm just wondering why you need code to create a shortcut?
0
 

Author Comment

by:paulmcneil
ID: 24019914
I've isolated the problem. My shortcut string has the forward slash for the wrkgrp switch and that / keeps getting converted to a back slash by the TargetPath property even if a I use the ascii code for /, it still flips the / to \.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24019946
try escaping it

did it work using .Arguments ?
0
 

Author Comment

by:paulmcneil
ID: 24020300
rockiroads,
What do you mean trying escaping it?
0
 

Author Comment

by:paulmcneil
ID: 24020349
Escaping does not work
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 65

Expert Comment

by:rockiroads
ID: 24020360
Put a \ before the /
like this   \/wrkgrp

eg

strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34) & " " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _
 & " \/wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24020376
yes your right, I just tried it
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24020403
but using .arguments like I said earlier seems to do the trick. I just gave it a test

strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34)
strArguments = Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _
 & " /wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)
 
Set WSHShortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")
With WSHShortcut
    .TargetPath = strShortcutTarget
    .Arguments = strArguments

0
 

Author Comment

by:paulmcneil
ID: 24020566
rockiroads,

Now I'm using this test code and it doesn't create the shortcut at all.
Dim myWSH As Object

Dim wshshortcut As Object

Dim fs As Object
 

Set fs = CreateObject("Scripting.FileSystemObject")
 

If fs.FileExists("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk") = True Then

  fs.deletefile ("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")

End If
 

Set myWSH = CreateObject("WScript.Shell")
 

strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34)

strArguments = Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _

 & " /wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)

 

Set wshshortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")

With wshshortcut

    .TargetPath = strShortcutTarget

    .Arguments = strArguments

End With

Open in new window

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24020626
I took your original code that you posted and added just strArguments

Dim myWSH As Object
Dim strAccessPath As String
Dim strShortcutTarget As String
Dim WSHShortcut
Dim strArguments As String
 
Set myWSH = CreateObject("WScript.Shell")
strAccessPath = myWSH.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Access\InstallRoot\Path")
strAccessPath = strAccessPath & "MSACCESS.EXE"
strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34)
strArguments = Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _
 & " /wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)
 
Set WSHShortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")
With WSHShortcut
    .TargetPath = strShortcutTarget
    .Arguments = strArguments
    .IconLocation = strAccessPath & ",1"
    .WorkingDirectory = "C:\"
    .Save
End With
Set myWSH = Nothing
Set WSHShortcut = Nothing


And it created a shortcut (I deleted it first) with a target path of

"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" /wrkgrp "C:\BWPhysicianOrg\BWPOBillingCoding.mdw"

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24020637
in the last code you posted, you had forgotten to add

.Save

also did you intentionally remove the stting of the icon and working directory?
0
 

Author Closing Comment

by:paulmcneil
ID: 31564330
thanks rockiroads I really appreciate it
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now