Skocz do zawartości

Rekomendowane odpowiedzi

Opublikowano

Mam problem. Co nie gra w tym kodzie??

To skrtypt, argument0 to nazwa tworzonego skrótu, argument1 to nazwa pliku, do odnośnika.

 

KOD:

 

///////////////////////////////////////////////////////////////

//name:

// creat_shortcut

//

//script type:

// function script

//

//autor:

// Ben Strasser alias Dr.Voodoo

//

//argument0:

// The path to the place of the shortcut

//

//argument1:

// The path to the target of the shortcut. Note that this file must exist.

//

//remarque:

// This script creats shortcuts using js but some Anti-virus programs

// simply block all script or ask for confirmation from the user.

// The game will freeze until the Anti-virus program is finished.

// In most cases this gives a little hicup an the shortcut is not created

// If the Anti-virus program ask for confirmation by the user the

// game will freeze until the user has made his chose. This script is

// no virus even if some Anti-virus say it could be.

//

//remarque2:

// The script returns if it has been sucsessful.

//

//remarque3:

// It wont work if the windows directory is not X:\windows\ (where

// X is an uperclase letter (so also A, C, E, Z, etc)).

//

//copyright:

// Ben Strasser

//

//web:

// http://de.geocities.com/ben0032003/

//

///////////////////////////////////////////////////////////////

var argument0_bak,temp,wscript,System_directory;

argument0_bak=argument0;

//check argument0

if string_copy(argument0,string_length(argument0)-3,4)!='.lnk'

argument0+='.lnk';

if string_copy(argument0,2,1)!=':'

argument0=working_directory+'\'+argument0;

if string_pos(argument0,'\')

{

show_error('create shortcut script : error in argument0; Please check if the path is legal',false);

return(false)

};

temp=1;

repeat(string_length(argument0))

{

if string_copy(argument0,temp,1)=='\'

{

argument0=string_insert('\',argument0,temp);

temp+=1

};

temp+=1

};

//check argument2

if file_exists(argument1)==false

{

show_error("create shortcut script : error in argument1; File doesn't exsit!",false);

return(false)

};

temp=1;

repeat(string_length(argument1))

{

if string_copy(argument1,temp,1)=='\'

{

argument1=string_insert('\',argument1,temp);

temp+=1

};

temp+=1

};

//search for Wscript

registry_set_root(1);

wscript=registry_read_string_ext('\SOFTWARE\Microsoft\Windows Scripting Host\Locations','WScript')

//search for windows directory

System_directory='C:\Windows\';

if file_exists('C:\Windows\NOTEPAD.EXE')==false

System_directory='no windows';

temp=ord('A');

repeat(26)

{

if System_directory=='no windows'

if file_exists(chr(temp)+':\Windows\NOTEPAD.EXE')

System_directory=chr(temp)+':\Windows\';

temp+=1

};

if System_directory=='no windows'

{

show_error('create shortcut script : unable to find windows directory',false);

exit

};

//convert Wscript path

wscript=string_replace(wscript,'%SystemRoot%',System_directory)

//writing js script

file_open_write('temp.js');

file_write_string('var WSHShell = WScript.CreateObject("WScript.Shell");');file_writeln();

file_write_string('var Path1 = "'+argument0+'";');file_writeln();

file_write_string('var Path2 = "'+argument1+'";');file_writeln();

file_write_string('var MyShortcut = WSHShell.CreateShortcut(Path1);');file_writeln();

file_write_string('MyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings(Path2);');file_writeln();

file_write_string('MyShortcut.Save()');file_writeln();

file_close();

//executing js script using wscript

execute_program(wscript,'temp.js',true);

//removing tem files

file_delete('temp.js');

if file_exists(argument0_bak)

return(true);

return(false)

//////////////////////////////////////////////////////////////////////////

  • Filar Społeczności
Opublikowano

Marmot, ile razy mam ci powtarzać. Zmiennych w GM nie trzeba deklarować. Po to się używa var, by potem taka zmienna po wykonaniu danego skryptu została zniszczona.

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...