Как подписать пакетный файл Windows (.bat)?

16892

Я использую Windows 7, и когда я пытаюсь запустить командный файл, он говорит: «Издатель не может быть проверен. Вы уверены, что хотите запустить это программное обеспечение?»

Поэтому, когда я пытаюсь подписать его с помощью сертификата для подписи кода, появляется сообщение «Ошибка SignTool. Этот формат файла не может быть подписан, поскольку он не распознан».

Так что я застрял между скалой и трудным местом. Есть ли способ устранить любое сообщение?

Скриншот

8
Переписать его как скрипт PowerShell и подписать? Я никогда не слышал о подписанных пакетных файлах. Iszi 11 лет назад 1
Вы не подписываете пакетные файлы. Похоже, ваш пакетный файл вызывает что-то еще, что должно быть подписано. Mark Allen 11 лет назад 0
Каков источник подсказки? То есть что такое заголовок и иконка? Это на самом деле приглашение Windows или приглашение сторонней программы безопасности? Сделайте скриншот и добавьте его к вопросу. Synetech 11 лет назад 1
http://windowsxp.mvps.org/networkfile.htm SeanC 11 лет назад 0
@SeanCheshire, если это так, то Techturtle это правильно; Windows просматривает все подозрительные данные в сети, поэтому вам нужно будет либо скопировать их локально, либо добавить местоположение в доверенную зону. Synetech 11 лет назад 0

3 ответа на вопрос

4
Mark Allen

You don't sign batch files. It sounds like your batch file is calling something else that should be signed.

Edit: Now that you've posted a batch file, we can see that it's because of the network location. Or, sometimes it'll happen if you merely copy a file from a network location. In the latter case, it's because Windows has tagged the file via an Alternate Data Stream to be in some other Internet zone. You can get around this one of two ways:

  1. Change your security zones in Internet Explorer, for the Intranet zone.
  2. Use the type command to destroy the Alternate Data Stream for the file. (There's also streams.exe from Sysinternals that can do it.) type thefile.bat > %temp%\newfile.bat & type %temp%\newfile.bat > thefile.bat
3
Synetech

What you are seeing is a general prompt that Windows provides whenever you try to open any time of file that has been downloaded. What happens is that when you download a file, it is tagged with a flag that indicates that it came from the Internet and is thus potentially dangerous. When you try to run such a file, Windows checks to see if it has a valid signature in order to determine if it can be trusted.

What you can do is to strip the flag from the file by using the Unblock button in the file’s properties, after which, Windows will leave you alone whenever you try to run it:

enter image description here


The problem is that batch-files are text-files that can be executed. While it is possible to sign a text-file, it will end up appending a bunch of binary data to the file which for a batch-file is bad because it is gibberish and will cause problems when the command-interpreter tries to execute it. Commenting out the signature will not work either because then the signature becomes corrupt.

Therefore, signing a batch file is not going to work.

What you need to do is to figure out why the system is prompting you when trying to run it. By default, Windows does not ask before running batch-files, so you must have a either a special policy or security program blocking it. Check your security program(s) to see if there is a verification setting that you can disable or add an exclusion for.

Also check the batch-file’s contents to see if it is running an executable that is not signed (though again, by default, Windows does not prompt for executables unless it was downloaded or requires elevated privileges, so check your settings).

Вы должны быть в состоянии выйти из сценария, прежде чем выполнение достигнет подписи, нет? Sparr 11 лет назад 0
@ Спарр, да и нет. Вы можете вставить `goto: eof` перед подписью, но тогда это изменит хеш файла и сделает подпись недействительной и, следовательно, файл будет поврежден / небезопасен. Я полагаю, у вас может быть строка в конце файла * перед * подписью, хотя, и это должно работать. Интересный эксперимент, чтобы попробовать ... Synetech 11 лет назад 0
Вы можете использовать команду типа - даже для двоичных файлов - чтобы разметить файл. Я делаю это все время. введите oldfile> newfile (а затем) введите newfile> oldfile, чтобы получить старый файл без тега ADS. Mark Allen 11 лет назад 2
Хе-хе, умный. Технически это не снимает флаг (и я не уверен, насколько он быстрее или удобнее, чем диалог * Свойства *, но он работает. Synetech 11 лет назад 0
3
techturtle

I get a similar message if I run batch files (or other executables) from a network location. If this is the case, you may want to consider moving it to a local drive. Another alternative is to use a separate batch file on the local drive to launch the one on the network. The launching batch file need only have one line in it:

@call \\network\folder\batch.bat 

Windows won't balk at the local file, and once that file is running, it can call the network version without issue.

@Sosukodo, так что `E:` это сетевой диск? Synetech 11 лет назад 0
Вроде ;-) Я управляю гостем VirtualBox Windows 7 на хосте Mac. E: является общей папкой VirtualBox. Я не знал, что общая папка будет считаться сетевым диском, но когда вы упомянули об этом, это имело смысл. 11 лет назад 0