ASP in the server side to create shortcuts example of the Microsoft Example transformation version.

Source: Internet
Author: User
Create | server | shortcuts | Microsoft has given us an example of creating a shortcut, but if used directly in ASP it prompts for an error.
Examples of the original code are as follows (VBScript format):
' Windows script Host Sample Script
'
' ------------------------------------------------------------------------
' Copyright (C) 1996-1997 Microsoft Corporation
'
' You have a royalty-free right to use, modify, reproduce and distribute
' The Sample application Files (and/or any modified version) in any way
' You find useful, provided, agree, Microsoft has no warranty,
' obligations or liability for any Sample application Files.
' ------------------------------------------------------------------------


' This sample demonstrates the WshShell object to create a shortcut
' On the desktop.

L_welcome_msgbox_message_text = "This script will create a shortcut to Notepad on your desktop. "
L_welcome_msgbox_title_text = "Windows Scripting Host Example"
Call Welcome ()

' ********************************************************************************
' *
' * Shortcut related methods.
' *

Dim WshShell
Set WshShell = WScript.CreateObject ("Wscript.Shell")

Pay attention to this sentence, I do not know whether it is wrong or Microsoft can make it run, anyway, I run on the hint no object. I changed it to: Set WshShell = server. CreateObject ("Wscript.Shell")

Dim MyShortcut, MyDesktop, DesktopPath

' Read Desktop path using Wshspecialfolders object
DesktopPath = Wshshell.specialfolders ("Desktop")

' Create a shortcut object on the desktop
Set MyShortcut = wshshell.createshortcut (DesktopPath & "\notepad shortcuts. lnk")

' Set shortcut object properties and save it
Myshortcut.targetpath = wshshell.expandenvironmentstrings ("%windir%\notepad.exe")
Myshortcut.workingdirectory = wshshell.expandenvironmentstrings ("%windir%")
Myshortcut.windowstyle = 4
Myshortcut.iconlocation = WSHShell.ExpandEnvironmentStrings ("%windir%\notepad.exe, 0")
Myshortcut.save

WScript.Echo "A shortcut to Notepad already exists on the desktop. "

' ********************************************************************************
' *
' * Welcome
' *
Sub Welcome ()
Dim Intdoit

Intdoit = MsgBox (L_welcome_msgbox_message_text, _
vbOKCancel + vbinformation, _
L_welcome_msgbox_title_text)
If Intdoit = vbcancel Then
Wscript.Quit
End If
End Sub

The following is my transformation after the use of the ASP.
<%l_welcome_msgbox_message_text = "This script will create a shortcut to Notepad on your desktop. "
L_welcome_msgbox_title_text = "Windows Scripting Host Example"
Response.Write L_welcome_msgbox_message_text
Dim WshShell
Set WshShell = server. CreateObject ("Wscript.Shell")
Dim MyShortcut, MyDesktop, DesktopPath
DesktopPath = Wshshell.specialfolders ("Desktop")
Set MyShortcut = wshshell.createshortcut (DesktopPath & "\notepad shortcuts. lnk")
Myshortcut.targetpath = wshshell.expandenvironmentstrings ("%windir%\notepad.exe")
Myshortcut.workingdirectory = wshshell.expandenvironmentstrings ("%windir%")
Myshortcut.windowstyle = 4
Myshortcut.iconlocation = WSHShell.ExpandEnvironmentStrings ("%windir%\notepad.exe, 0")
Myshortcut.save
Response.Write <BR> Shortcuts created! "
%>

has been tested on my NT4 pass.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.